File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Cannot insert null into a non nullable column Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Cannot insert null into a non nullable column" Watch "Cannot insert null into a non nullable column" New topic
Author

Cannot insert null into a non nullable column

anagha desai
Greenhorn

Joined: May 08, 2008
Posts: 22
Hello ,
Am new to JPA / Hibernate / ORM

Facing a strange issue .

1 >Created a simple table in HSQLDB
2 >Then using JPA tried persisting the data - and it worked fine

Here in DB had not defined the primary key explicitly

Now I tried to use the "Embedded" attribute
( Single Table - but two Java objects )

The problem that I am facing is that if I use :

it works fine

For other options ( AUTO , IDENTITY ) get the exception ::
Caused by: java.sql.SQLException: Attempt to insert null into a non-nullable column: column: CUST_ID

Can anyone provide some pointers related to ::
1 >
when I dont use @embedded & @Embeddable I can simply do an insert using GenerationType.AUTO - This works

2 >
when I use @embedded & @Embeddable I CANNOT do an insert unless I use
GenerationType.SEQUENCE

Thanks ,
anagha
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Sorry, I might just be confused, but embedded objects won't have an @Id on it, since it is a dependant object on another object, and that object will have the pk.

Embedded is a case where, for example, you have this table, and you want two seperate objects in Java to represent all the stuff in that one table.

Example

Table User
Fields:

id
firstname
lastname
street
city
state
zip

And you want a User and an Address object to represent all the fields in that User table.

Address object doesn't have the id, it is in the User object. So Address is an Embedded object for the User object.

Hope that helps clear some things up if I am correctly understanding what you are asking.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot insert null into a non nullable column
 
Similar Threads
JPA Auto Incrementing EmbeddedId (Composit primary key values).
GenerationType.AUTO
Problem with JPA Embeddable class field in Embedded
JPA Auto Incrementing EmbeddedId (Composit primary key values).
one to one unidirectional mapping in jpa