Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » [Unidirectional OneToOne Relationships] eclipselink doesn't understand MapsId=" "
[Unidirectional OneToOne Relationships] eclipselink doesn't understand MapsId=" " [message #531581] Wed, 05 May 2010 13:25 Go to next message
Gilberto Caetano de Andrade is currently offline Gilberto Caetano de AndradeFriend
Messages: 45
Registered: July 2009
Member
OS: opensuse 11.2
java: openjdk 1.6
eclipselink: 2.0.2

persistence-2_0-final-spec.pdf:
"If the dependent entity has a single primary key attribute (i.e, the relationship attribute or an attribute that corresponds to the relationship attribute) and the primary key of the parent entity is a simple primary key, the primary key of the dependent entity is a simple primary key of the same type as that of the parent entity (and neither EmbeddedId nor IdClass is specified). In this case, either (1) the relationship attribute is annotated Id, or (2) a separate Id attribute is specified and the relationship attribute is annotated MapsId (and the value element of the MapsId annotation is not specified)."

I'm using second one with orm.xml:
    <entity class="Person">
        <!-- CREATE TABLE PERSON (
            ID INTEGER NOT NULL,
            ADDRESS VARCHAR(100),
            NAME VARCHAR(100) NOT NULL,
            P_TYPE CHAR(2) NOT NULL, //NATURALPERSON(NP) OR LEGALENTITY(LE)
            VERSION SMALLINT NOT NULL
            CONSTRAINT PERSON_PKEY PRIMARY KEY (ID)
        );
        -->
        <table name="person"/>
        <inheritance strategy="JOINED"/>
        <discriminator-column name="p_type" column-definition="CHAR(2)" length="2" discriminator-type="STRING"/>
        <attributes>
            <id name="id">
                <column name="id"/>
                <generated-value strategy="AUTO"/>
            </id>
            <basic name="name">
                <column length="100"/>
            </basic>
            <basic name="address">
                <column length="100"/>
            </basic>
            <version name="version"/>
        </attributes>
    </entity>
    <entity class="Customer">
        <!--
            CREATE TABLE CUSTOMER (
                PERSON_ID INTEGER NOT NULL,
                PAYMENT_DAY INTEGER,
                CONSTRAINT CUSTOMER_PK PRIMARY KEY (PERSON_ID)
            );
        -->
        <table name="customer"/>
        <named-query name="Customer.findAll">
            <query>SELECT l FROM Customer l</query>
            <!--hint name="javax.persistence.cacheRetrieveMode"  value="CacheRetrieveMode.BYPASS"/-->
        </named-query>
        <named-query name="Customer.deleteById">
            <query>DELETE FROM Customer l WHERE l.id = :id</query>
        </named-query>
        <attributes>
            <id name="id">
                <column name="person_id"/>
            </id>
            <basic name="paymentDay">
                <column name="payment_day"/>
            </basic>
            <one-to-many name="vehicles" target-entity="Vehicle" mapped-by="customer"/>
            <one-to-one name="person" target-entity="Person" maps-id="">
                <join-column name="person_id" referenced-column-name="id" />
            </one-to-one>

        </attributes>
    </entity>

Eclipselink complains about it:
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running park.model.LegalEntityTest
[EL Config]: 2010-05-05 09:33:12.129--ServerSession(15020576)--Thread(Thread[main,5,main])--The access type for the persistent class [class park.model.Customer] is set to [FIELD].
[EL Config]: 2010-05-05 09:33:12.162--ServerSession(15020576)--Thread(Thread[main,5,main])--The access type for the persistent class [class park.model.Vehicle] is set to [FIELD].
[EL Config]: 2010-05-05 09:33:12.169--ServerSession(15020576)--Thread(Thread[main,5,main])--The target entity (reference) class for the many to one mapping element [field customer] is being defaulted to: class park.model.Customer.
[EL Config]: 2010-05-05 09:33:12.17--ServerSession(15020576)--Thread(Thread[main,5,main])--The target entity (reference) class for the many to one mapping element [field priceTable] is being defaulted to: class park.model.PriceTable.
[EL Config]: 2010-05-05 09:33:12.171--ServerSession(15020576)--Thread(Thread[main,5,main])--The target entity (reference) class for the many to one mapping element [field vType] is being defaulted to: class park.model.VehicleType.
[EL Config]: 2010-05-05 09:33:12.172--ServerSession(15020576)--Thread(Thread[main,5,main])--The access type for the persistent class [class park.model.VehicleType] is set to [FIELD].
[EL Config]: 2010-05-05 09:33:12.173--ServerSession(15020576)--Thread(Thread[main,5,main])--The access type for the persistent class [class park.model.Person] is set to [FIELD].
[EL Config]: 2010-05-05 09:33:12.174--ServerSession(15020576)--Thread(Thread[main,5,main])--The access type for the persistent class [class park.model.LegalEntity] is set to [FIELD].
[EL Config]: 2010-05-05 09:33:12.177--ServerSession(15020576)--Thread(Thread[main,5,main])--The access type for the persistent class [class park.model.NaturalPerson] is set to [FIELD].
[EL Config]: 2010-05-05 09:33:12.178--ServerSession(15020576)--Thread(Thread[main,5,main])--The access type for the persistent class [class park.model.PriceTable] is set to [FIELD].
[EL Config]: 2010-05-05 09:33:12.18--ServerSession(15020576)--Thread(Thread[main,5,main])--The alias name for the entity class [class park.model.Customer] is being defaulted to: Customer.
[EL Config]: 2010-05-05 09:33:12.189--ServerSession(15020576)--Thread(Thread[main,5,main])--The table schema for entity [file:/home/gilberto/dev/netbeans-config/park-jpa/core/target/classes/META-INF/orm.xml] is being defaulted to: park.
[EL Config]: 2010-05-05 09:33:12.223--ServerSession(15020576)--Thread(Thread[main,5,main])--The alias name for the entity class [class park.model.Vehicle] is being defaulted to: Vehicle.
[EL Config]: 2010-05-05 09:33:12.224--ServerSession(15020576)--Thread(Thread[main,5,main])--The table schema for entity [file:/home/gilberto/dev/netbeans-config/park-jpa/core/target/classes/META-INF/orm.xml] is being defaulted to: park.
[EL Config]: 2010-05-05 09:33:12.225--ServerSession(15020576)--Thread(Thread[main,5,main])--The alias name for the entity class [class park.model.VehicleType] is being defaulted to: VehicleType.
[EL Config]: 2010-05-05 09:33:12.225--ServerSession(15020576)--Thread(Thread[main,5,main])--The table schema for entity [file:/home/gilberto/dev/netbeans-config/park-jpa/core/target/classes/META-INF/orm.xml] is being defaulted to: park.
[EL Config]: 2010-05-05 09:33:12.227--ServerSession(15020576)--Thread(Thread[main,5,main])--The alias name for the entity class [class park.model.Person] is being defaulted to: Person.
[EL Config]: 2010-05-05 09:33:12.227--ServerSession(15020576)--Thread(Thread[main,5,main])--The table schema for entity [file:/home/gilberto/dev/netbeans-config/park-jpa/core/target/classes/META-INF/orm.xml] is being defaulted to: park.
[EL Config]: 2010-05-05 09:33:12.241--ServerSession(15020576)--Thread(Thread[main,5,main])--The column name for element [field address] is being defaulted to: ADDRESS.
[EL Config]: 2010-05-05 09:33:12.242--ServerSession(15020576)--Thread(Thread[main,5,main])--The column name for element [field name] is being defaulted to: NAME.
[EL Config]: 2010-05-05 09:33:12.243--ServerSession(15020576)--Thread(Thread[main,5,main])--The column name for element [field version] is being defaulted to: VERSION.
[EL Config]: 2010-05-05 09:33:12.247--ServerSession(15020576)--Thread(Thread[main,5,main])--The alias name for the entity class [class park.model.LegalEntity] is being defaulted to: LegalEntity.
[EL Config]: 2010-05-05 09:33:12.247--ServerSession(15020576)--Thread(Thread[main,5,main])--The table schema for entity [file:/home/gilberto/dev/netbeans-config/park-jpa/core/target/classes/META-INF/orm.xml] is being defaulted to: park.
[EL Config]: 2010-05-05 09:33:12.249--ServerSession(15020576)--Thread(Thread[main,5,main])--The primary key column name for the inheritance class [class park.model.LegalEntity] is being defaulted to: id.
[EL Config]: 2010-05-05 09:33:12.253--ServerSession(15020576)--Thread(Thread[main,5,main])--The alias name for the entity class [class park.model.NaturalPerson] is being defaulted to: NaturalPerson.
[EL Config]: 2010-05-05 09:33:12.254--ServerSession(15020576)--Thread(Thread[main,5,main])--The table schema for entity [file:/home/gilberto/dev/netbeans-config/park-jpa/core/target/classes/META-INF/orm.xml] is being defaulted to: park.
[EL Config]: 2010-05-05 09:33:12.254--ServerSession(15020576)--Thread(Thread[main,5,main])--The primary key column name for the inheritance class [class park.model.NaturalPerson] is being defaulted to: id.
[EL Config]: 2010-05-05 09:33:12.255--ServerSession(15020576)--Thread(Thread[main,5,main])--The alias name for the entity class [class park.model.PriceTable] is being defaulted to: PriceTable.
[EL Config]: 2010-05-05 09:33:12.258--ServerSession(15020576)--Thread(Thread[main,5,main])--The table schema for entity [file:/home/gilberto/dev/netbeans-config/park-jpa/core/target/classes/META-INF/orm.xml] is being defaulted to: park.
[EL Info]: 2010-05-05 09:33:12.675--ServerSession(15020576)--Thread(Thread[main,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.0.2.v20100323-r6872
[EL Fine]: 2010-05-05 09:33:13.256--Thread(Thread[main,5,main])--Detected Vendor platform: org.eclipse.persistence.platform.database.H2Platform
[EL Config]: 2010-05-05 09:33:13.277--ServerSession(15020576)--Connection(27109735)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
        platform=>H2Platform
        user name=> "park"
        datasource URL=> "jdbc:h2:../parkDB;create=true;MODE=PostgreSQL;DB_CLOSE_DELAY=-1"
))
[EL Config]: 2010-05-05 09:33:13.28--ServerSession(15020576)--Connection(7245716)--Thread(Thread[main,5,main])--Connected: jdbc:h2:../parkDB
        User: PARK
        Database: H2  Version: 1.2.131 (2010-03-05)
        Driver: H2 JDBC Driver  Version: 1.2.131 (2010-03-05)
[EL Config]: 2010-05-05 09:33:13.281--ServerSession(15020576)--Connection(9715140)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
        platform=>H2Platform
        user name=> "park"
        datasource URL=> "jdbc:h2:../parkDB;create=true;MODE=PostgreSQL;DB_CLOSE_DELAY=-1"
))
[EL Config]: 2010-05-05 09:33:13.283--ServerSession(15020576)--Connection(6503761)--Thread(Thread[main,5,main])--Connected: jdbc:h2:../parkDB
        User: PARK
        Database: H2  Version: 1.2.131 (2010-03-05)
        Driver: H2 JDBC Driver  Version: 1.2.131 (2010-03-05)
[EL Severe]: 2010-05-05 09:33:13.361--ServerSession(15020576)--Thread(Thread[main,5,main])--Local Exception Stack: 
Exception [EclipseLink-0] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Exception [EclipseLink-48] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.DescriptorException
[COLOR=blue]Exception Description: Multiple writable mappings exist for the field [park.customer.person_id].  Only one may be defined as writable, all others must be specified read-only.
[/COLOR]Mapping: org.eclipse.persistence.mappings.OneToOneMapping[person]
Descriptor: RelationalDescriptor(park.model.Customer --> [DatabaseTable(park.customer)])

Runtime Exceptions: 
---------------------------------------------------------

        at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:478)
        at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
        at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:671)
        at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:620)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:369)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:151)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:207)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:195)
        at park.model.LegalEntityTest.initEntityManager(LegalEntityTest.java:39)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
        at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
        at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
        at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)



What is wrong with my config?

Regards,

Gilberto
Re: [Unidirectional OneToOne Relationships] eclipselink doesn't understand MapsId=" " [message #531984 is a reply to message #531581] Thu, 06 May 2010 17:02 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

I don't think this is what MapsId is for, from its JavaDoc,

"Designates a ManyToOne or OneToOne relationship attribute that provides the mapping for an EmbeddedId primary key"

Sounds like it is only to handle a special case of EmbeddedId.

For your model you need to either mark the <id> or the <join-column> as read-only (insertable/updateable=false).

You could also use a PrimaryKeyJoinColumn, or not define the id and just use the one-to-one as the id.


James : Wiki : Book : Blog : Twitter
Re: [Unidirectional OneToOne Relationships] eclipselink doesn't understand MapsId=" " [message #532025 is a reply to message #531984] Thu, 06 May 2010 19:47 Go to previous messageGo to next message
Gilberto Caetano de Andrade is currently offline Gilberto Caetano de AndradeFriend
Messages: 45
Registered: July 2009
Member
James wrote on Thu, 06 May 2010 13:02
I don't think this is what MapsId is for, from its JavaDoc,

"Designates a ManyToOne or OneToOne relationship attribute that provides the mapping for an EmbeddedId primary key"

Sounds like it is only to handle a special case of EmbeddedId.

For your model you need to either mark the <id> or the <join-column> as read-only (insertable/updateable=false).

You could also use a PrimaryKeyJoinColumn, or not define the id and just use the one-to-one as the id.



But as per JSR-317 Final Release it is neither EmbeddedId nor IdClass.
My case is similar to the example (4): case (b), on page 35 of the specification.

JSR-317 Final Release note:
Quote:

[15] Note that the use of PrimaryKeyJoinColumn instead of MapsId would result in the same mapping in this example. Use of MapsId is preferred for the mapping of derived identities.



Gilberto Caetano de Andrade
www.secad.to.gov.br
blog.gilbertoca.com
Re: [Unidirectional OneToOne Relationships] eclipselink doesn't understand MapsId=" " [message #532289 is a reply to message #532025] Fri, 07 May 2010 19:18 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Please file a bug for this, as EclipseLink is incorrectly processing the maps-id defaults from xml. Using maps-id=" " (with a whitespace) may work, but maps-id="id" will definetely workaround the issue.

Best Regards,
Chris
Re: [Unidirectional OneToOne Relationships] eclipselink doesn't understand MapsId=" " [message #532302 is a reply to message #532289] Fri, 07 May 2010 20:36 Go to previous message
Gilberto Caetano de Andrade is currently offline Gilberto Caetano de AndradeFriend
Messages: 45
Registered: July 2009
Member
Ok, done! Bug 312128

Thanks for your attention,

Gilberto
Previous Topic:Delay betwen persist and find of a relationship
Next Topic:dynamically configure javax.persistence.jdbc.url?
Goto Forum:
  


Current Time: Thu Apr 25 22:00:15 GMT 2024

Powered by FUDForum. Page generated in 0.03035 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top