Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » TableGenerator - Sequence/ID Generation(TableGenerator Id Generation With Custom Table)
TableGenerator - Sequence/ID Generation [message #1174837] Thu, 07 November 2013 05:43 Go to next message
Babji Chetty is currently offline Babji Chetty
Messages: 2
Registered: November 2013
Junior Member
I'm working on a JAVAEE Enterprise application, which has the technology stack: Glassfish 3.1, EJB 3.1, EclipseLink 2.4.2, SQL Server 2008 R2. In the EJB module, I have a couple of entities which use SequenceGenerator's and a couple of entities with TableGenerator's.

The SequenceGenerator's are working fine, but the TableGenerator's aren't. I tried to check the server.log by setting the EclipseLink's logging to '**FINEST**', but I don't see any queries logged for getting the next value of the Id. The EJB entity that uses TableGenerator is as below:

@Entity
    @Table(name = "TEST")
    @TableGenerator(name = "test_gen", table = "ID_GENERATOR", pkColumnName = "ID_NAME", pkColumnValue = "TEST", valueColumnName = "ID_VAL", allocationSize = 50, initialValue = 1)
    public class Test extends SuperClass implements Interface1, Interface2, Interface3, Interface4, Interface5, Serializable {
        private static final long serialVersionUID = 5084413459400887388L;
    	
        /** The id of the entry.
         */
        protected long id = 0;
    	
        @Id
        @GeneratedValue(strategy = GenerationType.TABLE, generator = "test_gen")
        @Column(name = "NWTID", nullable = false, updatable = false)
        @Override
        public long getId() {
            return id;
        }
    	
    	.....
    
    }


**Note**: The Table 'ID_GENERATOR' is used by all entities with TableGenerator annotation, with a Unique Generator name.

After checking the logs with '**FINEST**' setting, I tried many other ways, but couldn't get the 'TableGenerator' working. Later, I downloaded the EclipseLink's (2.4.2) sources and debugged the 'Sequencing' mechanism, during deployment, as well as at application runtime. During deployment, I found the Sequence 'TEST' to be initialized, but at runtime, the Id's are not being generated.

BTW, my persistence.xml has a couple of datasources, with the following properties for EclipseLink:

<persistence-unit name="TestCtx" transaction-type="JTA">
            <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
            <jta-data-source>TESTDS</jta-data-source>
            <properties>
                <property name="eclipselink.target-database"  value="SQLServer"/>
                <property name="eclipselink.query-results-cache" value="false"/>
                <property name="eclipselink.cache.shared.default" value="false"/>            
                <property name="eclipselink.weaving" value="static"/>
                <property name="eclipselink.id-validation" value="NULL"/>
                <property name="javax.persistence.validation.mode" value="NONE"/>
                <property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
                <property name="eclipselink.logging.thread" value="false"/>
                <property name="eclipselink.logging.session" value="false"/>
                <property name="eclipselink.logging.timestamp" value="false"/>
                <property name="eclipselink.logging.exceptions" value="false"/>
            </properties>
        </persistence-unit>


Do you have any clue, as to what's happening here?
Re: TableGenerator - Sequence/ID Generation [message #1181283 is a reply to message #1174837] Mon, 11 November 2013 08:58 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1018
Registered: July 2009
Senior Member
This looks like a cross post of http://stackoverflow.com/questions/19823833/eclipselink-and-tablegenerator-id-not-generated

if so, then the issue was with using the "eclipselink.allow-zero-id" property to allow 0 to be used as an ID instead of having them generated.
Re: TableGenerator - Sequence/ID Generation [message #1187885 is a reply to message #1181283] Fri, 15 November 2013 05:30 Go to previous message
Babji Chetty is currently offline Babji Chetty
Messages: 2
Registered: November 2013
Junior Member
Chris: Thanks for posting it. As explained in that cross post, the 2 EclipseLink's pesistence.xml properties disable the sequence generation for TableGenerator's. There's no proper documentation, as to why this is like that...but trying different test cases, I have found the solution to my problem.
Previous Topic:NamedPLSQLStoredProcedureQuery with multiple out parameters
Next Topic:javax.naming.NoInitialContextException with DatabaseSession
Goto Forum:
  


Current Time: Fri Aug 29 18:27:36 EDT 2014

Powered by FUDForum. Page generated in 0.10879 seconds