Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] JoinColumn ManyToOne set to null on INSERT

Disclaimer: I am not a J2EE developer so I don't have any proper background in this (so please excuse me when I get the lingo wrong).

I am trying to migrate an old (now unsupported) app from Glassfish-2.6 to Glassfish-3.0.1 and have tried to simply switch the JPA from the old toplink essentials to eclipselink 2.0. When 2.0 didn't seem to work, I made a switch to 2.2.0, but still have the same issue. I am building/deploying on Windows XP using NetBeans 6.9.1, and persisting to a remote Oracle-XE instance.

Under the original configuration, the App worked fine, but now it doesn't. In essence, there are 2 entities that need to be persisted to 2 tables of the database and one has a foreign key reference to the other. Unfortunately, when the persistence takes place, a new row is written to each table, but the foreign key is set to null.

The source for the entities is here:

http://code.google.com/p/icat-dataportal/source/browse/branches/dataminx0/coreutil/src/uk/ac/dl/dp/coreutil/entity/Session.java

http://code.google.com/p/icat-dataportal/source/browse/branches/dataminx0/coreutil/src/uk/ac/dl/dp/coreutil/entity/FacilitySession.java

But the following are the relevant parts, I believe:

public class Session implements Serializable {
    
    @Id
    @TableGenerator(name="SESSION", table="SEQUENCE", pkColumnName="SEQ_NAME", pkColumnValue="SESSION",valueColumnName="SEQ_COUNT")
    @GeneratedValue(strategy=GenerationType.TABLE,generator="SESSION")
    @Column(name = "ID", nullable = false)
    private Long id;
    
and
public class FacilitySession implements Serializable {
    
    @Id
    @GeneratedValue(strategy=GenerationType.TABLE,generator="SEQ_GEN")
    @Column(name = "ID", nullable = false)
    private Long id;

    @JoinColumn(name = "DP_SESSION_ID", referencedColumnName = "ID", nullable=false)
    @ManyToOne(optional = false)
    private Session sessionId;
My persistence.xml
 <persistence-unit name="dataportal" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/dataportal</jta-data-source>
    <class>uk.ac.dl.dp.coreutil.entity.Session</class>
    <class>uk.ac.dl.dp.coreutil.entity.FacilitySession</class>
     -- snip --
    <properties>
      <property name="eclipselink.target-server" value="SunAS9"/>
      <property name="eclipselink.logging.level" value="FINER"/>
      <property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.DefaultSessionLog"/>
     <property name="eclipselink.cache.shared.default" value="false"/>
      <property name="eclipselink.cache.type.default" value="NONE"/>
      <property name="eclipselink.cache.size.default" value="0"/>
      <property name="eclipselink.weaving" value="static"/>
I get the same result regardless of setting weaving static or not.

This is just some logging preamble

INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: [EL Info]: 2011-06-02 14:53:22.626--ServerSession(31641045)--Thread(Thread[http-thread-pool-8181-(1),10,Grizzly])
   --EclipseLink, version: Eclipse Persistence Services - 2.2.0.v20110202-r8913

INFO: [EL Fine]: 2011-06-02 14:53:23.517--Thread(Thread[http-thread-pool-8181-(1),10,Grizzly])
    --Detected Vendor platform: org.eclipse.persistence.platform.database.oracle.Oracle10Platform

INFO: [EL Config]: 2011-06-02 14:53:23.611--ServerSession(31641045)--Connection(6140210)--Thread(Thread[http-thread-pool-8181-(1),10,Grizzly])
    --connecting(DatabaseLogin(
        platform=>DatabasePlatform
        user name=> ""
        connector=>JNDIConnector datasource name=>null
))


FINE: Detected Vendor platform: org.eclipse.persistence.platform.database.oracle.Oracle10Platform
CONFIG: connecting(DatabaseLogin(
        platform=>DatabasePlatform
        user name=> ""
        connector=>JNDIConnector datasource name=>null
))
CONFIG: Connected: jdbc:oracle:thin:@localhost:1521:XE
        User: ICAT
        Database: Oracle  Version: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
        Driver: Oracle JDBC driver  Version: 10.1.0.5.0
INFO: [EL Fine]: 2011-06-02 14:54:59.126--ServerSession(31641045)--Connection(15782157)--Thread(Thread[http-thread-pool-8181-(2),10,Grizzly])
    --SELECT ID, FACILITY_NAME, FACILITY_SESSION_ERROR, FACILITY_SESSION_ID, MOD_TIME, DP_SESSION_ID FROM DP_FACILITY_SESSION WHERE (DP_SESSION_ID = ?)
        bind => [1501]

This is relevant because it uses some kind of lookup table generator to produce the session table ID ...

INFO: [EL Finer]: 2011-06-02 14:54:59.361--ClientSession(4559681)--Thread(Thread[http-thread-pool-8181-(2),10,Grizzly])
    --TX beginTransaction, status=STATUS_ACTIVE

INFO: [EL Fine]: 2011-06-02 14:54:59.361--ClientSession(4559681)--Connection(4372717)--Thread(Thread[http-thread-pool-8181-(2),10,Grizzly])
    --UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
        bind => [50, SESSION]

INFO: [EL Fine]: 2011-06-02 14:54:59.454--ClientSession(4559681)--Connection(4372717)--Thread(Thread[http-thread-pool-8181-(2),10,Grizzly])
    --SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = ?
        bind => [SESSION]

INFO: [EL Finer]: 2011-06-02 14:54:59.486--ClientSession(4559681)--Thread(Thread[http-thread-pool-8181-(2),10,Grizzly])
    --TX beginTransaction, status=STATUS_ACTIVE

INFO: [EL Fine]: 2011-06-02 14:54:59.548--ClientSession(4559681)--Connection(4372717)--Thread(Thread[http-thread-pool-8181-(2),10,Grizzly])
    --UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
        bind => [50, SEQ_GEN]

INFO: [EL Fine]: 2011-06-02 14:54:59.564--ClientSession(4559681)--Connection(4372717)--Thread(Thread[http-thread-pool-8181-(2),10,Grizzly])
    --SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = ?
        bind => [SEQ_GEN]

INFO: file:/H:/doug/Workspace/icatproject/icat-CSAF/dist/gfdeploy/icat-CSAF/icat3-api-ws_jar/_icat3-exposed login successful
INFO: [EL Finer]: 2011-06-02 14:54:59.673--UnitOfWork(30307940)--Thread(Thread[http-thread-pool-8181-(2),10,Grizzly])
    --begin unit of work flush

INFO: [EL Finer]: 2011-06-02 14:54:59.72--ClientSession(4559681)--Thread(Thread[http-thread-pool-8181-(2),10,Grizzly])
    --TX beginTransaction, status=STATUS_ACTIVE

INFO: [EL Fine]: 2011-06-02 14:54:59.767--ClientSession(4559681)--Connection(4372717)--Thread(Thread[http-thread-pool-8181-(2),10,Grizzly])
    --UPDATE DP_USER SET MOD_TIME = ? WHERE (ID = ?)
        bind => [2011-06-02 14:54:59.751, 1]

This is persisting the two entities. First it saves the session, after which presumably it now knows the foreign key (ID) for adding into the @JoinColumn item DP_SESSION_ID, But it goes in as null. I have no idea why. And less idea how to fix it.

INFO: [EL Fine]: 2011-06-02 14:54:59.767--ClientSession(4559681)--Connection(4372717)--Thread(Thread[http-thread-pool-8181-(2),10,Grizzly])
    --INSERT INTO DP_SESSION (ID, CREDENTIAL, CREDENTIAL_TYPE, EXPIRE_DATE_TIME, MOD_TIME, USER_SESSION_ID, USER_ID) VALUES (?, ?, ?, ?, ?, ?, ?)
        bind => [1551, certificate not used!, PROXY, 2011-06-02 16:48:56.173, 2011-06-02 14:54:59.47, 8088463d-3c67-456f-9f79-c578ffb5e0c4, 1]

INFO: [EL Fine]: 2011-06-02 14:54:59.861--ClientSession(4559681)--Connection(4372717)--Thread(Thread[http-thread-pool-8181-(2),10,Grizzly])
    --INSERT INTO DP_FACILITY_SESSION (ID, FACILITY_NAME, FACILITY_SESSION_ERROR, FACILITY_SESSION_ID, MOD_TIME, DP_SESSION_ID) VALUES (?, ?, ?, ?, ?, ?)
        bind => [1551, CSAF, null, 1de95dac-1fa4-411c-8a6b-4144e0dbf61e, 2011-06-02 14:54:59.658, null]

INFO: [EL Finer]: 2011-06-02 14:54:59.97--UnitOfWork(30307940)--Thread(Thread[http-thread-pool-8181-(2),10,Grizzly])
    --end unit of work flush

Help! Thanks

P.S. Just for reference, my glassfish\modules folder has these files:

22/12/2010  07:45 AM           126,856 javax.persistence_2.0.3.v201010191057.jar
09/02/2011  08:56 AM           191,857 org.eclipse.persistence.antlr_2.2.0.v20110202-r8913.jar
09/02/2011  08:56 AM           236,938 org.eclipse.persistence.asm_2.2.0.v20110202-r8913.jar
09/02/2011  08:56 AM         4,349,385 org.eclipse.persistence.core_2.2.0.v20110202-r8913.jar
09/02/2011  08:56 AM            47,837 org.eclipse.persistence.jpa.modelgen_2.2.0.v20110202-r8913.jar
09/02/2011  08:56 AM           859,627 org.eclipse.persistence.jpa_2.2.0.v20110202-r8913.jar
09/02/2011  08:56 AM            80,370 org.eclipse.persistence.oracle_2.2.0.v20110202-r8913.jar


View this message in context: JoinColumn ManyToOne set to null on INSERT
Sent from the EclipseLink - Users mailing list archive at Nabble.com.

Back to the top