You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by tfriess <tf...@de.ibm.com> on 2011/05/12 10:14:54 UTC
OpenJPA 1.2.2: Persisting/ Retrieving List or other Java
build-in types using @PersistentCollection
Hello,
I have a problem in persisting/ retrieving an entity containing a
List<String> as field using OpenJPA Version 1.2.2. (I have to use OpenJPA
1.x and can not use OpenJPA 2.x).
I have searched in the archive of this mailing list and the web but didn't
found a solution for me. In general @PersistentCollection seems to work
here, but I still have problems:
I tried both ways for the configuration: Using Annotations in the entity
class or an orm.xml - it didn't change anything.
Using the orm.xml I marked this field with the <basic .../> tag, with
Annotations I used @PersistentCollection.
Persisting such an entity works fine, for both configuration ways OpenJPA
creates an additional table in the database that hold the lists values; if
an entity with such an list is persisted, I can see the data stored
correctly in the database (using a client tool to access the DB directly).
The problem arises when I try to fetch such objects out of the database
using a Query. (It seems to work sometimes for the PersistentManager.find
method when you know the PK for an object). When I execute a query
Query q = em.createQuery("SELECT myt FROM MYTABLE myt");
and then call q.getResultList()
I get an exception
Exception in thread "main" <openjpa-1.2.2-r422266:898935 nonfatal general
error> org.apache.openjpa.persistence.PersistenceException: java.lang.String
incompatible with org.apache.openjpa.enhance.PersistenceCapable
[...]
Caused by: java.lang.ClassCastException: java.lang.String incompatible with
org.apache.openjpa.enhance.PersistenceCapable
I observed that I can query for such entities without any problem when there
are no values for the List<String> field of the entity (when the list is
empty), but as soon as I add some values to it and persist such an entity, I
get this problem.
I would appreciate any help,
thank you very much!
Kind regards,
Tim
--
View this message in context: http://openjpa.208410.n2.nabble.com/OpenJPA-1-2-2-Persisting-Retrieving-List-String-or-other-Java-build-in-types-using-PersistentCollectn-tp6354895p6354895.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: OpenJPA 1.2.2: Persisting/ Retrieving List or other Java
build-in types using @PersistentCollection
Posted by Rick Curtis <cu...@gmail.com>.
Tim -
It looks like this was fixed in 2.0.0[1].
[1] https://issues.apache.org/jira/browse/OPENJPA-1020
Thanks,
Rick
On Thu, May 12, 2011 at 10:05 AM, tfriess <tf...@de.ibm.com> wrote:
>
> Rick Curtis wrote:
> >
> > Tim -
> >
> > Can you post your Entity and the full exception stack?
> >
>
> Hello Rick,
> thank you for your fast response.
>
> I went through my code once again and I think I've found the problem,
> it seems to be the FetchType of such an PersistentCollection.
> When I annotate such a List<String> with
> @PersistentCollection(fetch=FetchType.EAGER)
> I get the following Exception thrown:
>
> Exception in thread "main" <openjpa-1.2.2-r422266:898935 nonfatal general
> error> org.apache.openjpa.persistence.PersistenceException:
> java.lang.String
> incompatible with org.apache.openjpa.enhance.PersistenceCapable
> at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:894)
> at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:793)
> at
>
> org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:986)
> at
> org.apache.openjpa.jdbc.sql.AbstractResult.load(AbstractResult.java:278)
> at
>
> org.apache.openjpa.jdbc.sql.SelectImpl$SelectResult.load(SelectImpl.java:2413)
> at
> org.apache.openjpa.jdbc.sql.AbstractResult.load(AbstractResult.java:272)
> at
>
> org.apache.openjpa.jdbc.kernel.InstanceResultObjectProvider.getResultObject(InstanceResultObjectProvider.java:59)
> at
> org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:36)
> at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1228)
> at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:990)
> at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:805)
> at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:775)
> at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:771)
> at
> org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:517)
> at
> org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:255)
> at
> org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:294)
> at testing.Test.main(Test.java:55)
> Caused by: java.lang.ClassCastException: java.lang.String incompatible with
> org.apache.openjpa.enhance.PersistenceCapable
> at
>
> org.apache.openjpa.jdbc.kernel.JDBCStoreManager.setInverseRelation(JDBCStoreManager.java:408)
> at
>
> org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initializeState(JDBCStoreManager.java:380)
> at
>
> org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initialize(JDBCStoreManager.java:278)
> at
>
> org.apache.openjpa.kernel.DelegatingStoreManager.initialize(DelegatingStoreManager.java:111)
> at
>
> org.apache.openjpa.kernel.ROPStoreManager.initialize(ROPStoreManager.java:57)
> at
> org.apache.openjpa.kernel.BrokerImpl.initialize(BrokerImpl.java:913)
> at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:871)
> ... 16 more
>
>
> But if I use @PersistentCollection(fetch=FetchType.LAZY) or only
> @PersistentCollection,
> everything works fine.
>
> Does this mean that such a PersistentCollection only can be loaded "lazy"
> in
> OpenJPA 1.x?
> Or is there any way to load such a List "eager"?
>
> Thank you!
>
> Kind regards,
> Tim
>
> --
>
--
*Rick Curtis*
Re: OpenJPA 1.2.2: Persisting/ Retrieving List or other
Java build-in types using @PersistentCollection
Posted by tfriess <tf...@de.ibm.com>.
Rick Curtis wrote:
>
> Tim -
>
> Can you post your Entity and the full exception stack?
>
Hello Rick,
thank you for your fast response.
I went through my code once again and I think I've found the problem,
it seems to be the FetchType of such an PersistentCollection.
When I annotate such a List<String> with
@PersistentCollection(fetch=FetchType.EAGER)
I get the following Exception thrown:
Exception in thread "main" <openjpa-1.2.2-r422266:898935 nonfatal general
error> org.apache.openjpa.persistence.PersistenceException: java.lang.String
incompatible with org.apache.openjpa.enhance.PersistenceCapable
at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:894)
at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:793)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:986)
at org.apache.openjpa.jdbc.sql.AbstractResult.load(AbstractResult.java:278)
at
org.apache.openjpa.jdbc.sql.SelectImpl$SelectResult.load(SelectImpl.java:2413)
at org.apache.openjpa.jdbc.sql.AbstractResult.load(AbstractResult.java:272)
at
org.apache.openjpa.jdbc.kernel.InstanceResultObjectProvider.getResultObject(InstanceResultObjectProvider.java:59)
at
org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:36)
at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1228)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:990)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:805)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:775)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:771)
at
org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:517)
at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:255)
at
org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:294)
at testing.Test.main(Test.java:55)
Caused by: java.lang.ClassCastException: java.lang.String incompatible with
org.apache.openjpa.enhance.PersistenceCapable
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.setInverseRelation(JDBCStoreManager.java:408)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initializeState(JDBCStoreManager.java:380)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initialize(JDBCStoreManager.java:278)
at
org.apache.openjpa.kernel.DelegatingStoreManager.initialize(DelegatingStoreManager.java:111)
at
org.apache.openjpa.kernel.ROPStoreManager.initialize(ROPStoreManager.java:57)
at org.apache.openjpa.kernel.BrokerImpl.initialize(BrokerImpl.java:913)
at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:871)
... 16 more
But if I use @PersistentCollection(fetch=FetchType.LAZY) or only
@PersistentCollection,
everything works fine.
Does this mean that such a PersistentCollection only can be loaded "lazy" in
OpenJPA 1.x?
Or is there any way to load such a List "eager"?
Thank you!
Kind regards,
Tim
--
View this message in context: http://openjpa.208410.n2.nabble.com/OpenJPA-1-2-2-Persisting-Retrieving-List-String-or-other-Java-build-in-types-using-PersistentCollectn-tp6354895p6356104.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: OpenJPA 1.2.2: Persisting/ Retrieving List or other Java
build-in types using @PersistentCollection
Posted by Rick Curtis <cu...@gmail.com>.
Tim -
Can you post your Entity and the full exception stack?
Thanks,
Rick
On Thu, May 12, 2011 at 3:14 AM, tfriess <tf...@de.ibm.com> wrote:
> Hello,
> I have a problem in persisting/ retrieving an entity containing a
> List<String> as field using OpenJPA Version 1.2.2. (I have to use OpenJPA
> 1.x and can not use OpenJPA 2.x).
> I have searched in the archive of this mailing list and the web but didn't
> found a solution for me. In general @PersistentCollection seems to work
> here, but I still have problems:
>
> I tried both ways for the configuration: Using Annotations in the entity
> class or an orm.xml - it didn't change anything.
> Using the orm.xml I marked this field with the <basic .../> tag, with
> Annotations I used @PersistentCollection.
>
> Persisting such an entity works fine, for both configuration ways OpenJPA
> creates an additional table in the database that hold the lists values; if
> an entity with such an list is persisted, I can see the data stored
> correctly in the database (using a client tool to access the DB directly).
>
> The problem arises when I try to fetch such objects out of the database
> using a Query. (It seems to work sometimes for the PersistentManager.find
> method when you know the PK for an object). When I execute a query
> Query q = em.createQuery("SELECT myt FROM MYTABLE myt");
> and then call q.getResultList()
> I get an exception
> Exception in thread "main" <openjpa-1.2.2-r422266:898935 nonfatal general
> error> org.apache.openjpa.persistence.PersistenceException:
> java.lang.String
> incompatible with org.apache.openjpa.enhance.PersistenceCapable
> [...]
> Caused by: java.lang.ClassCastException: java.lang.String incompatible with
> org.apache.openjpa.enhance.PersistenceCapable
>
> I observed that I can query for such entities without any problem when
> there
> are no values for the List<String> field of the entity (when the list is
> empty), but as soon as I add some values to it and persist such an entity,
> I
> get this problem.
>
> I would appreciate any help,
> thank you very much!
>
> Kind regards,
> Tim
>