Hi Frank,
I'm very glad to hear that you are trying out some of the new JPA 2.0
features. I've found that the issue you found isn't specific to OpenJPA
2.0. This problem also exists on previous releases (1.0.2) of OpenJPA. In
short, if an entity is defined only in the orm.xml and not all fields are
defined, an exception is thrown. Annotating the class with @Entity or
defining all fields in the orm.xml corrects the problem.
This entity definition corrected the problem:
<entity class="....model.Person" name="Person" access="FIELD">
<table name="PERSON" />
<attributes>
<id name="id">
<generated-value strategy="SEQUENCE" />
</id>
<basic name="firstName"/>
<basic name="lastName"/>
<element-collection name="addresses" />
<attributes>
</entity>
Based on what I've read in the JPA spec, this looks like a bug. OpenJPA
should consider firstName and lastName persistent fields by default. I've
opened JIRA OPENJPA-859 <https://issues.apache.org/jira/browse/OPENJPA-859> for
this issue.
-Jeremy
On Sun, Jan 11, 2009 at 12:45 PM, Frank Schwarz <[email protected]> wrote:
>
> Hi,
>
>
> testing some of the advertised JPA2 features (see
>
> http://openjpa.apache.org/2008/12/23/openjpa-20-iteration-1-is-complete.html
>
> http://openjpa.apache.org/2008/12/23/openjpa-20-iteration-1-is-complete.html
> ) I came across an issue with collections of primitives:
>
> model:
>
> entity Person with fields long id, String firstName, String lastName,
> Set<String> addresses
>
> mapping is done via orm.xml:
>
> <entity class="....model.Person" name="Person" access="FIELD">
> <table name="PERSON" />
> <attributes>
> <id name="id">
> <generated-value strategy="SEQUENCE" />
> </id>
> <element-collection name="addresses" />
> </attributes>
> </entity>
>
>
> This gives me an irritating exception about missing metadata for firstName
> and lastName:
>
> Exception in thread "main"
> org.apache.openjpa.persistence.ArgumentException: Fields
> "....Person.firstName, ....model.Person.lastName" are not a default
> persistent type, and do not have any annotations indicating their
> persistence strategy. If you do not want these fields to be persisted,
> annotate them with @Transient.
> at
>
> org.apache.openjpa.persistence.PersistenceMetaDataFactory.validateStrategies(PersistenceMetaDataFactory.java:399)
> at
>
> org.apache.openjpa.persistence.PersistenceMetaDataFactory.load(PersistenceMetaDataFactory.java:205)
> at
>
> org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepository.java:474)
> at
>
> org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:294)
> at
>
> org.apache.openjpa.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:286)
> at
> org.apache.openjpa.jdbc.meta.MappingTool.getMapping(MappingTool.java:676)
> at
> org.apache.openjpa.jdbc.meta.MappingTool.buildSchema(MappingTool.java:748)
> at
> org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:646)
> at
>
> org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:153)
> at
>
> org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFactory.java:119)
> at
>
> org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:196)
> at
>
> org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
> at
>
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:197)
> at
>
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:150)
> at
>
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:61)
> at
>
> oopex.openjpa2.jpa2.relationships.CollectionOfPrimitivesMain.insert(CollectionOfPrimitivesMain.java:69)
> at
>
> oopex.openjpa2.jpa2.relationships.CollectionOfPrimitivesMain.main(CollectionOfPrimitivesMain.java:49)
>
>
>
> A bug?
>
>
> -- Frank
> --
> View this message in context:
> http://n2.nabble.com/orm.xml---element-collection---trunk-tp2142331p2142331.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>