You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by sanga lawalata <sa...@gmail.com> on 2008/12/08 20:17:30 UTC
Unit Testing with openEjb
I have this error code while try to persist this entity bean.
it seems that It can get the sequence number from oracle dual sequence.
Below I put also the ddl.
Any advice ?
WARN - Unexpected exception from beforeCompletion; transaction will roll
back
<openjpa-1.1.0-r422266:659716 nonfatal general error>
org.apache.openjpa.persistence.PersistenceException:
null
at
org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.getConnection(AbstractJDBCSeq.java:162)
at
org.apache.openjpa.jdbc.kernel.NativeJDBCSeq.nextInternal(NativeJDBCSeq.java:209)
at
org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java:60)
at
org.apache.openjpa.util.ImplHelper.generateValue(ImplHelper.java:160)
at
org.apache.openjpa.util.ImplHelper.generateFieldValue(ImplHelper.java:144)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignField(JDBCStoreManager.java:592)
at
org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:464)
at
org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:440)
this is my EntityBean,
[code]
@Entity
@Table(name = "myTable")
public class TestBean implements Comparable<TestBean>,
Serializable {
@Transient
private static final long serialVersionUID = 6555325804020146762L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE,generator =
"SEQ_TESTSEQUENCE" )
@SequenceGenerator(name = "SEQ_TESTSEQUENCE", sequenceName =
"SEQ_TESTSEQUENCE",allocationSize=1)
private long id;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CREATED", nullable = false)
private Date created;
@Column(name = "ERROR_MESSAGE", nullable = false,length=200)
private String errorMessage;
[/code]
and this my persistence.xml
[code]
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="NCDError">
<jta-data-source>java:/DefaultDS</jta-data-source>
<class>my.package.TestBean</class>
</persistence-unit>
</persistence>
[/code]
My DDL :
[code]
CREATE SEQUENCE "DEV001"."SEQ_TESTSEQUENCE" MINVALUE 1 MAXVALUE
999999999999999999999999999 INCREMENT BY 1 START WITH 2500000060 CACHE 20
NOORDER NOCYCLE ;
[/code]
best regards
sanga lawalata
Re: Unit Testing with openEjb
Posted by Kevin Sutter <kw...@gmail.com>.
Hi Sanga,
I need a couple of clarifications to help diagnose your situation. If I'm
reading this right, you are attempting to run your test with and without the
following property in your persistence.xml. Is that right?
<properties>
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)" />
</properties>
This property tells OpenJPA to use the mappings defined by your object model
(Entity annotations and/or xml) and then make the database schema "right".
The documentation for this option can be found here:
http://openjpa.apache.org/builds/1.2.0/apache-openjpa-1.2.0/docs/manual/manual.html#ref_guide_mapping_mappingtool(the
mapping tool options are used for the SynchronizeMappings property).
But, from your note below, it sounds like you are using an existing
application and database, so you probably don't want to modify the schema
dynamically with that option. You might want to use the "validate" option
instead of the "buildSchema" to ensure that your object mappings do match
your schema definitions. If they do not match, then an error message should
be produced that will explain the differences.
Let's start with that. Take a look at the OpenJPA doc reference that I
provided, try out the validate option for the SynchronizeMappings, and let's
determine if we're in the right ball park before we go much further.
Providing your Entity mappings may also help with diagnosing the situation.
Thanks,
Kevin
On Wed, Dec 10, 2008 at 12:40 PM, David Blevins <da...@visi.com>wrote:
> Hi Sanga,
>
> Hoping the OpenJPA folks have some insight on the error.
>
> -David
>
> On Dec 9, 2008, at 2:35 AM, sanga lawalata wrote:
>
> Greetings,
>>
>> I know the problem is that there is no in my persistence XML.
>>
>> <properties>
>> <property name="openjpa.jdbc.SynchronizeMappings"
>> value="buildSchema(ForeignKeys=true)" />
>> </properties>
>>
>>
>> but I get problems here that in DB :
>> Table User (number id, varchar name, number address_id). And the
>> address_id
>> can be null.
>> Table Address(number id, varchar description)
>>
>> I map the User table into entity UserBean for example and set my addressId
>> as null because I dont need it.
>>
>> if i delete in my persitence.xml the "xml fragment upstair (property
>> fragment)", i will get error message
>>
>> <openjpa-1.1.0-r422266:659716 nonfatal general error>
>> org.apache.openjpa.persistence.PersistenceException: null
>> at
>>
>> org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.getConnection(AbstractJDBCSeq.java:162)
>> at
>>
>> org.apache.openjpa.jdbc.kernel.NativeJDBCSeq.nextInternal(NativeJDBCSeq.java:209)
>>
>> If I put in my persitence.xml the "xml fragment upstair (property
>> fragment)", i will get error message
>> <openjpa-1.1.0-r422266:659716 nonfatal general error>
>> org.apache.openjpa.persistence.PersistenceException: Table "User" has a
>> foreign key to table "Address" that has not been generated. You must run
>> the schema generator on all inter-related tables at once.
>>
>> i just want to insert and delete into User table using UserEntity and set
>> the addressId as null because later addressId can be taken from another
>> class who deals with it. (I am working with already existing application
>> and
>> db).
>>
>> Any advice guys to deal with this situation ??
>>
>> best regards
>> sanga lawalata
>>
>
>
Re: Unit Testing with openEjb
Posted by Sanga Lawalata <sl...@jamba.net>.
Greetings,
I think i know the problems. My situation is I use real database and
not in memory database. So forgot 2 things which are :
1. I forgot to specify the ORM inside my persistence UML. So i put
hibernate inside the persitence.xml
2. I forgot to put also the OracleDialect.
After the two of them are in persistence XML, the openEJB can perist my
entity.
best regards
sanga lawalata
Re: Unit Testing with openEjb
Posted by Kevin Sutter <kw...@gmail.com>.
Hi Sanga,
I need a couple of clarifications to help diagnose your situation. If I'm
reading this right, you are attempting to run your test with and without the
following property in your persistence.xml. Is that right?
<properties>
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)" />
</properties>
This property tells OpenJPA to use the mappings defined by your object model
(Entity annotations and/or xml) and then make the database schema "right".
The documentation for this option can be found here:
http://openjpa.apache.org/builds/1.2.0/apache-openjpa-1.2.0/docs/manual/manual.html#ref_guide_mapping_mappingtool(the
mapping tool options are used for the SynchronizeMappings property).
But, from your note below, it sounds like you are using an existing
application and database, so you probably don't want to modify the schema
dynamically with that option. You might want to use the "validate" option
instead of the "buildSchema" to ensure that your object mappings do match
your schema definitions. If they do not match, then an error message should
be produced that will explain the differences.
Let's start with that. Take a look at the OpenJPA doc reference that I
provided, try out the validate option for the SynchronizeMappings, and let's
determine if we're in the right ball park before we go much further.
Providing your Entity mappings may also help with diagnosing the situation.
Thanks,
Kevin
On Wed, Dec 10, 2008 at 12:40 PM, David Blevins <da...@visi.com>wrote:
> Hi Sanga,
>
> Hoping the OpenJPA folks have some insight on the error.
>
> -David
>
> On Dec 9, 2008, at 2:35 AM, sanga lawalata wrote:
>
> Greetings,
>>
>> I know the problem is that there is no in my persistence XML.
>>
>> <properties>
>> <property name="openjpa.jdbc.SynchronizeMappings"
>> value="buildSchema(ForeignKeys=true)" />
>> </properties>
>>
>>
>> but I get problems here that in DB :
>> Table User (number id, varchar name, number address_id). And the
>> address_id
>> can be null.
>> Table Address(number id, varchar description)
>>
>> I map the User table into entity UserBean for example and set my addressId
>> as null because I dont need it.
>>
>> if i delete in my persitence.xml the "xml fragment upstair (property
>> fragment)", i will get error message
>>
>> <openjpa-1.1.0-r422266:659716 nonfatal general error>
>> org.apache.openjpa.persistence.PersistenceException: null
>> at
>>
>> org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.getConnection(AbstractJDBCSeq.java:162)
>> at
>>
>> org.apache.openjpa.jdbc.kernel.NativeJDBCSeq.nextInternal(NativeJDBCSeq.java:209)
>>
>> If I put in my persitence.xml the "xml fragment upstair (property
>> fragment)", i will get error message
>> <openjpa-1.1.0-r422266:659716 nonfatal general error>
>> org.apache.openjpa.persistence.PersistenceException: Table "User" has a
>> foreign key to table "Address" that has not been generated. You must run
>> the schema generator on all inter-related tables at once.
>>
>> i just want to insert and delete into User table using UserEntity and set
>> the addressId as null because later addressId can be taken from another
>> class who deals with it. (I am working with already existing application
>> and
>> db).
>>
>> Any advice guys to deal with this situation ??
>>
>> best regards
>> sanga lawalata
>>
>
>
Re: Unit Testing with openEjb
Posted by David Blevins <da...@visi.com>.
Hi Sanga,
Hoping the OpenJPA folks have some insight on the error.
-David
On Dec 9, 2008, at 2:35 AM, sanga lawalata wrote:
> Greetings,
>
> I know the problem is that there is no in my persistence XML.
>
> <properties>
> <property name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema(ForeignKeys=true)" />
> </properties>
>
>
> but I get problems here that in DB :
> Table User (number id, varchar name, number address_id). And the
> address_id
> can be null.
> Table Address(number id, varchar description)
>
> I map the User table into entity UserBean for example and set my
> addressId
> as null because I dont need it.
>
> if i delete in my persitence.xml the "xml fragment upstair (property
> fragment)", i will get error message
>
> <openjpa-1.1.0-r422266:659716 nonfatal general error>
> org.apache.openjpa.persistence.PersistenceException: null
> at
> org
> .apache
> .openjpa
> .jdbc.kernel.AbstractJDBCSeq.getConnection(AbstractJDBCSeq.java:162)
> at
> org
> .apache
> .openjpa.jdbc.kernel.NativeJDBCSeq.nextInternal(NativeJDBCSeq.java:
> 209)
>
> If I put in my persitence.xml the "xml fragment upstair (property
> fragment)", i will get error message
> <openjpa-1.1.0-r422266:659716 nonfatal general error>
> org.apache.openjpa.persistence.PersistenceException: Table "User"
> has a
> foreign key to table "Address" that has not been generated. You
> must run
> the schema generator on all inter-related tables at once.
>
> i just want to insert and delete into User table using UserEntity
> and set
> the addressId as null because later addressId can be taken from
> another
> class who deals with it. (I am working with already existing
> application and
> db).
>
> Any advice guys to deal with this situation ??
>
> best regards
> sanga lawalata
Re: Unit Testing with openEjb
Posted by David Blevins <da...@visi.com>.
Hi Sanga,
Hoping the OpenJPA folks have some insight on the error.
-David
On Dec 9, 2008, at 2:35 AM, sanga lawalata wrote:
> Greetings,
>
> I know the problem is that there is no in my persistence XML.
>
> <properties>
> <property name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema(ForeignKeys=true)" />
> </properties>
>
>
> but I get problems here that in DB :
> Table User (number id, varchar name, number address_id). And the
> address_id
> can be null.
> Table Address(number id, varchar description)
>
> I map the User table into entity UserBean for example and set my
> addressId
> as null because I dont need it.
>
> if i delete in my persitence.xml the "xml fragment upstair (property
> fragment)", i will get error message
>
> <openjpa-1.1.0-r422266:659716 nonfatal general error>
> org.apache.openjpa.persistence.PersistenceException: null
> at
> org
> .apache
> .openjpa
> .jdbc.kernel.AbstractJDBCSeq.getConnection(AbstractJDBCSeq.java:162)
> at
> org
> .apache
> .openjpa.jdbc.kernel.NativeJDBCSeq.nextInternal(NativeJDBCSeq.java:
> 209)
>
> If I put in my persitence.xml the "xml fragment upstair (property
> fragment)", i will get error message
> <openjpa-1.1.0-r422266:659716 nonfatal general error>
> org.apache.openjpa.persistence.PersistenceException: Table "User"
> has a
> foreign key to table "Address" that has not been generated. You
> must run
> the schema generator on all inter-related tables at once.
>
> i just want to insert and delete into User table using UserEntity
> and set
> the addressId as null because later addressId can be taken from
> another
> class who deals with it. (I am working with already existing
> application and
> db).
>
> Any advice guys to deal with this situation ??
>
> best regards
> sanga lawalata
Re: Unit Testing with openEjb
Posted by sanga lawalata <sa...@gmail.com>.
Greetings,
I know the problem is that there is no in my persistence XML.
<properties>
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)" />
</properties>
but I get problems here that in DB :
Table User (number id, varchar name, number address_id). And the address_id
can be null.
Table Address(number id, varchar description)
I map the User table into entity UserBean for example and set my addressId
as null because I dont need it.
if i delete in my persitence.xml the "xml fragment upstair (property
fragment)", i will get error message
<openjpa-1.1.0-r422266:659716 nonfatal general error>
org.apache.openjpa.persistence.PersistenceException: null
at
org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.getConnection(AbstractJDBCSeq.java:162)
at
org.apache.openjpa.jdbc.kernel.NativeJDBCSeq.nextInternal(NativeJDBCSeq.java:209)
If I put in my persitence.xml the "xml fragment upstair (property
fragment)", i will get error message
<openjpa-1.1.0-r422266:659716 nonfatal general error>
org.apache.openjpa.persistence.PersistenceException: Table "User" has a
foreign key to table "Address" that has not been generated. You must run
the schema generator on all inter-related tables at once.
i just want to insert and delete into User table using UserEntity and set
the addressId as null because later addressId can be taken from another
class who deals with it. (I am working with already existing application and
db).
Any advice guys to deal with this situation ??
best regards
sanga lawalata