Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Sequences in SQL Server 2012 + JPA + Eclipselink
Sequences in SQL Server 2012 + JPA + Eclipselink [message #1075951] Tue, 30 July 2013 11:45
Anil Veldurthi is currently offline Anil Veldurthi
Messages: 1
Registered: July 2013
Junior Member
Hi,

I'm having an issue when trying to insert an object using JPA(provider: eclipselink, version: 2.5.0), jTds driver version 1.2.8 for database sql server 2012. I used SEQUENCE as generation strategy for the ID generation. Even though the sequence is created in the database the transaction is failed due to the following error:

java.sql.SQLException: Cannot insert the value NULL into column 'ID', table 'Test.dbo.TestTable'; column does not allow nulls. INSERT fails.

here is my JPA Object:
import java.io.Serializable;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "TestTable")
public class JPAObject implements Serializable {

private static final long serialVersionUID = 1L;

public JPAObject() {
super();
}

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IDSQE")
@SequenceGenerator(name = "IDSQE", sequenceName = "IDSQE", allocationSize = 1)
private Integer id;

@Column(name = "DESCRIPTION")
private String description;

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}
}

log:

[EL Config]: connection: 2013-07-30 13:12:56.357--ServerSession(1136341612)--Connection(718377354)--Thread(Thread[main,5,main])--Connected: jdbc:jtds:sqlserver://127.0.0.1:58535;databaseName=Test
User: app
Database: Microsoft SQL Server Version: 11.00.3128
Driver: jTDS Type 4 JDBC Driver for MS SQL Server and Sybase Version: 1.2.8
[EL Fine]: sql: 2013-07-30 13:12:56.419--ClientSession(1150114449)--Connection(718377354)--Thread(Thread[main,5,main])--INSERT INTO TestTable (DESCRIPTION) VALUES (?)
bind => [Test, null, 2013-07-30 13:12:56.404]
[EL Fine]: sql: 2013-07-30 13:12:56.425--ClientSession(1150114449)--Thread(Thread[main,5,main])--SELECT 1
[EL Warning]: 2013-07-30 13:12:56.427--UnitOfWork(1165235400)--Thread(Thread[main,5,main])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Cannot insert the value NULL into column 'ID', table 'Test.dbo.TestTable'; column does not allow nulls. INSERT fails.
Error Code: 515
Call: INSERT INTO TestTable (DESCRIPTION) VALUES (?)
bind => [Test]

Thanks in advance Smile

-Anil
Previous Topic:Problem with criteria
Next Topic:Schema generation script in JPA 2.1
Goto Forum:
  


Current Time: Thu Oct 30 14:33:29 GMT 2014

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

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