You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by fengyi <li...@sina.com> on 2013/07/03 07:33:02 UTC
[openjpa-2.2.1] when i cascade merge entity. a exception thrown
Hello everyone:
i configured two entity,mapped with oneToMany and manyToOne。 and i want
merge one enity and the
another entity could cascade merge. but it didn't work. an exception
occured. i can't confirm this exception whether reasonable!
@Entity
@Table(name="point_appcard")
public class PointAppCardEntity {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long appid;
private Date created = Calendar.getInstance().getTime();
private Date modified = Calendar.getInstance().getTime();
@OneToMany(mappedBy="appCard",fetch=FetchType.EAGER,cascade=CascadeType.MERGE)
private List<PointCardEntity> cards;
}
@Entity
@Table(name="point_card")
public class PointCardEntity {
@Id
private String cardno;
private Date created = Calendar.getInstance().getTime();
private Date modified = Calendar.getInstance().getTime();
@ManyToOne(fetch=FetchType.EAGER,cascade={CascadeType.MERGE})
@JoinTable(name="point_carddetail",
joinColumns=@JoinColumn(name="cardno",
referencedColumnName="cardno"),
inverseJoinColumns=@JoinColumn(name="appid",
referencedColumnName="appid"))
}
and the full stack trace is:
<openjpa-2.2.1-runknown nonfatal store error>
org.apache.openjpa.util.StoreException:
org.apache.openjpa.util.java$util$Date$proxy cannot be cast to
org.apache.openjpa.enhance.PersistenceCapable
at
org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:2000)
at org.apache.openjpa.kernel.LocalManagedRuntime.commit
(LocalManagedRuntime.java:81)
at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1516)
at
org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:933)
at org.apache.openjpa.persistence.EntityManagerImpl.commit
(EntityManagerImpl.java:570)
at
com.shangquan.test.pm.dao.TestPointAppCardDao.TestUpdatePointAppCardWithPointCard
(TestPointAppCardDao.java:201)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run
(JUnit3TestReference.java:130)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run
(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main
(RemoteTestRunner.java:197)
Caused by: java.lang.ClassCastException:
org.apache.openjpa.util.java$util$Date$proxy
cannot be cast to org.apache.openjpa.enhance.PersistenceCapable
at org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.update
(RelationFieldStrategy.java:374)
at
org.apache.openjpa.jdbc.meta.FieldMapping.update(FieldMapping.java:699)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.update
(AbstractUpdateManager.java:343)
at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.populateRowManager
(AbstractUpdateManager.java:174)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush
(AbstractUpdateManager.java:97)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush
(AbstractUpdateManager.java:78)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:735)
at org.apache.openjpa.kernel.DelegatingStoreManager.flush
(DelegatingStoreManager.java:131)
at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2176)
at
org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2074)
at
org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1992)
... 21 more
if anyone has encountered this exception before,any solutions avaliable?
thanks very much
--
View this message in context: http://openjpa.208410.n2.nabble.com/openjpa-2-2-1-when-i-cascade-merge-entity-a-exception-thrown-tp7584325.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: [openjpa-2.2.1] when i cascade merge entity. a exception thrown
Posted by fengyi <li...@sina.com>.
i belive this is because of the jpa enhance . i use the eclise default
compiler compile the source. and then use the ant to enhance the class file
that compiled. maybe the every time when i run the test,the class recompile
agin. now i change the ant build as the default compiler. the test past!
--
View this message in context: http://openjpa.208410.n2.nabble.com/openjpa-2-2-1-when-i-cascade-merge-entity-a-exception-thrown-tp7584325p7584333.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: [openjpa-2.2.1] when i cascade merge entity. a exception thrown
Posted by fengyi <li...@sina.com>.
I'm sorry,maybe i have some in hurry.
i found that this exception is thrown because i forgot to enhance the entity
after changing.
this is not a problem!
--
View this message in context: http://openjpa.208410.n2.nabble.com/openjpa-2-2-1-when-i-cascade-merge-entity-a-exception-thrown-tp7584325p7584327.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: [openjpa-2.2.1] when i cascade merge entity. a exception thrown
Posted by fengyi <li...@sina.com>.
by the way , the object is cascade fetch by another object. i don't know it's
a factor
--
View this message in context: http://openjpa.208410.n2.nabble.com/openjpa-2-2-1-when-i-cascade-merge-entity-a-exception-thrown-tp7584325p7584329.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: [openjpa-2.2.1] when i cascade merge entity. a exception thrown
Posted by fengyi <li...@sina.com>.
but at the same time , i find a strange thing,it's not reasonable.
when i query a object which have an date Field. after query,the entity
manager closed.
then i want set a new date
,ie:card.getModified().setTime(Calendar.getInstance().getTimeInMillis())
there is a exception:
<openjpa-2.2.1-runknown fatal user error>
org.apache.openjpa.persistence.InvalidStateException: The context has been
closed. The stack trace at which the context was closed is held in the
embedded exception.
if i set a new Date ,ie:
there is another
exception:card.setModified(Calendar.getInstance().getTime());
<openjpa-2.2.1-runknown nonfatal store error>
org.apache.openjpa.util.StoreException: java.util.Date cannot be cast to
org.apache.openjpa.enhance.PersistenceCapable
if i didn't modify the date:
the exception is :
<openjpa-2.2.1-runknown nonfatal store error>
org.apache.openjpa.util.StoreException:
org.apache.openjpa.util.java$util$Date$proxy cannot be cast to
org.apache.openjpa.enhance.PersistenceCapable
only i set null can update success. now i lose my self!
any tip?
or anyone knows which situation will encounter this error and explain this
thing.
i can avoid this situation use cascade merge as i mentioned above!
--
View this message in context: http://openjpa.208410.n2.nabble.com/openjpa-2-2-1-when-i-cascade-merge-entity-a-exception-thrown-tp7584325p7584328.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.