openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benjamin Renaud <benjamin.ren...@gmail.com>
Subject Problem using OpenJPAEntityManager#createInstance
Date Thu, 13 Nov 2008 07:03:55 GMT
Hi everyone,

I'm using 1.2.0, Glassfish (latest version), Java 6.

I am experimenting with the createInstance feature of OpenJPA.

Specifically, I wrote a stateless session bean (source code below) and  
ran into two problems:

1. the basic, simple case of simply calling

  TestPerstInterface i = (TestPerstInterface)em.createInstance(c);

fails with the message 'No metadata was found for managed interface  
com.gsi.starfish.server.data.TestPerstInterface'.

and 2. Working off the openjpa sources, I did a bunch of stuff to  
convince it that TestPerstInterface, and I've gotten it to instantiate  
the interface, but it fails at commit time after I try to persist it,  
with

  [httpSSLWorkerThread-8888-1] openjpa.Runtime - An exception occurred  
while ending the transaction.  This exception will be re-thrown.
<openjpa-1.2.0-r422266:683325 nonfatal store error>  
org.apache.openjpa.util.StoreException: ERROR: relation  
"openjpa_sequence_table" does not exist {prepstmnt 2101781704 SELECT  
SEQUENCE_VALUE FROM OPENJPA_SEQUENCE_TABLE WHERE ID = ? FOR UPDATE  
[params=(int) 0]} [code=0, state=42P01]

SynchronizeMappings is set to buildSchema in persistence.xml (the only  
setting of note).

Any thoughts?
Thanks,
Benjamin

@Stateless(mappedName = "test")
@Remote(Test.class)
public class TestBean {

     @PersistenceContext
     EntityManager normalEm;

    public Object test() throws Exception {
         Class c =  
Class.forName("com.gsi.starfish.server.data.TestPerstInterface");
         OpenJPAEntityManager em = OpenJPAPersistence.cast(normalEm);

--- Stuff I added after it couldn't find the meta data ---
         OpenJPAEntityManagerFactory factory =  
em.getEntityManagerFactory();
         OpenJPAEntityManagerFactorySPI spi =  
(OpenJPAEntityManagerFactorySPI)factory;
          
spi.getConfiguration().getMetaDataRepositoryInstance().register(c);
         ClassMetaData cmd =  
spi.getConfiguration().getMetaDataRepositoryInstance().addMetaData(c,  
ClassMetaData.MODE_ALL);
         cmd.setManagedInterface(true);
--- End Stuff ---

         TestPerstInterface i =  
(TestPerstInterface)em.createInstance(c);
         System.out.println("instance: " + i);
         i.setId(1);
         i.setFoo("foo!");
         i.setADate(new Date());
         normalEm.persist(i);
         return i;
     }
}

where TestPerstInterface looks like this:

@ManagedInterface
public interface TestPerstInterface extends Serializable {

     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     long getId();
     void setId(long id);

     @Column(nullable = false)
     String getFoo();
     void setFoo(String foo);

     @Temporal(value = TemporalType.TIMESTAMP)
     Date getADate();
     void setADate(Date aDate);
}


Mime
View raw message