On Feb 14, 2008, at 6:29 AM, <[EMAIL PROTECTED]> <[EMAIL PROTECTED]
> wrote:
Thanks a lot again, I have now made one errors progress:
Now the problem seems to be that the entities in the database are
not automatically created. Is this possible or do I have to do it on
my own?
Thanks,
Karsten
javax.ejb.EJBException: The bean encountered a non-application
exception.; nested exception is:
<openjpa-1.0.1-r420667:592145 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: Table 'tpg-
server.strecke' doesn't exist {prepstmnt 5511938 SELECT t0.id,
t0.name FROM strecke t0 WHERE (t0.name = ?) [params=(String) Meine
Strecke]} [code=1146, state=42S02]
Excellent. You're through all the hard stuff. This error here is
because the tables don't exist, which is very easy to fix. In your
persistence.xml file add the following OpenJPA specific property:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<persistence-unit name="movie-unit">
<!-- your other stuff -->
<properties>
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>
</properties>
</persistence-unit>
</persistence>
What this is going to do is tell OpenJPA to auto-create all your
tables, all your primary keys and all foreign keys exactly to match
your objects. A very excellent feature indeed.
You should be all set.
A warning in advance for any new JPA user, by default all objects will
detach at the end of a transaction; people typically discover this
when the go to remove or update an object they fetched previously and
get an exception like "You cannot perform operation delete on detached
object". The part that's sneaky is that a test case has no
transaction, so unless specified otherwise a transaction will start
and complete around each ejb method call and then as a result
persistent objects passed back as return values will detach.
There are a couple ways to deal with that.
The first is to use PersistenceContextType.EXTENDED for EntityManager
refs instead of the default of PersistenceContextType.TRANSACTION.
The "injection-of-entitymanager" example in our examples zip shows how
to do that. (it's also available here: http://svn.apache.org/repos/asf/openejb/tags/openejb-3.0-beta-2/examples/injection-of-entitymanager/)
The second is to use a technique to execute transactions in your test
code. That's described here: http://openejb.apache.org/3.0/unit-testing-transactions.html
-David