Home » Eclipse Projects » EclipseLink » DDL Generation & @GenerationType.IDENTITY(Automatically generated tables doesn't add identity to columns)
| |
Re: DDL Generation & @GenerationType.IDENTITY [message #1709103 is a reply to message #1709075] |
Thu, 24 September 2015 06:06 |
Andreas Fagschlunger Messages: 17 Registered: June 2011 |
Junior Member |
|
|
Hello Chris!
Here's the DDL statement for table creation:
CREATE TABLE MESSAGEENTITY (COMPANYID INTEGER, MESSAGEID INTEGER, SUBJECT VARCHAR(56), TEXT VARCHAR(1024), PRIMARY KEY (COMPANYID, MESSAGEID))
And this is what the INSERT Statement Looks like:
[EL Fine]: sql: 2015-09-24 07:50:06.127--ClientSession(1724457619)--Connection(2123960023)--Thread(Thread[main,5,main])--INSERT INTO MESSAGEENTITY (COMPANYID, SUBJECT, TEXT) VALUES (?, ?, ?)
bind => [1, Lorem ipsum ..., Lorem ipsum dolor sit amet ...]
The outcome is a SQLException:
Caused by: ERROR 23502: Column 'MESSAGEID' cannot accept a NULL value.
Properties are set as follow:
properties.put("javax.persistence.provider", "org.eclipse.persistence.jpa.PersistenceProvider");
properties.put(PersistenceUnitProperties.JDBC_URL, "jdbc:derby:memory:testDB2;create=true");
properties.put(PersistenceUnitProperties.TRANSACTION_TYPE, "RESOURCE_LOCAL");
properties.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.DROP_AND_CREATE);
properties.put(PersistenceUnitProperties.DDL_GENERATION_MODE, PersistenceUnitProperties.DDL_BOTH_GENERATION);
properties.put(PersistenceUnitProperties.LOGGING_PARAMETERS, Boolean.TRUE.toString());
properties.put(PersistenceUnitProperties.TARGET_DATABASE, TargetDatabase.Derby);
properties.put(PersistenceUnitProperties.LOGGING_LEVEL, SessionLog.FINER_LABEL);
Attached to this post you will find some Java source files to reproduce the Problem.
Best regards,
Andreas Fagschlunger
|
|
| | | |
Re: DDL Generation & @GenerationType.IDENTITY [message #1710190 is a reply to message #1709996] |
Mon, 05 October 2015 09:01 |
Andreas Fagschlunger Messages: 17 Registered: June 2011 |
Junior Member |
|
|
Hello Chris!
Yes, removing the columDefinition did the trick:
[EL Fine]: sql: 2015-10-05 10:54:48.159--ServerSession(1638172114)--Connection(335708295)--Thread(Thread[main,5,main])--CREATE TABLE MESSAGEENTITY (MESSAGEID INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL, COMPANYID INTEGER, SUBJECT VARCHAR(56), TEXT VARCHAR(1024), PRIMARY KEY (MESSAGEID))
This also answers my original question, adding "GENERATED BY DEFAULT AS IDENTITY NOT NULL" to the columnDefinition creates the column with identity.
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, columnDefinition = "INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL")
private Integer messageId;
Thank you.
|
|
| | |
Goto Forum:
Current Time: Thu Sep 26 00:17:45 GMT 2024
Powered by FUDForum. Page generated in 0.03737 seconds
|