File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Databases
»
Object Relational Mapping
Author
Problem with @GeneratedValue
Deepa Datar
Greenhorn
Joined: Jan 31, 2003
Posts: 4
posted
Feb 06, 2008 15:43:00
0
Hi All,
I have a simple Entity class.
import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import java.math.BigDecimal; import java.util.Date; @SuppressWarnings("serial") @Entity @Table(name = "demo_data") public class DemoData implements Serializable { private long demo_id; private String data_file; @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name = "demo_id") public long getDemo_id() { return demo_id; } public void setDemo_id(long demo_id) { this.demo_id = demo_id; } @Column(name = "data_file") public String getData_file() { return data_file; } public void setData_file(String data_file) { this.data_file = data_file; } }
When I execute the above code I get the following exception
16:54:29,311 DEBUG [JDBCExceptionReporter] could not insert: [com.dd.DemoData] [insert into demo_data (demo_id, data_file) values (?, ?)] java.sql.SQLException: Cannot insert the value NULL into column 'demo_id', table 'test.dbo.demo_data'; column does not allow nulls. INSERT fails.
Can anyone suggest where the problem lies?
Deepa Datar
Greenhorn
Joined: Jan 31, 2003
Posts: 4
posted
Feb 06, 2008 15:48:00
0
I am adding a record by calling
DemoData d = new DemoData(); d.setData_file("datafile.txt"); saveRecord(d);
private void saveRecord(DemoData d) { // save record in DB manager.persist(d); }
Thanks
Deepa Datar
Deepa Datar
Greenhorn
Joined: Jan 31, 2003
Posts: 4
posted
Feb 06, 2008 16:05:00
0
Its working now. I changed the
GenerationType
from AUTO to TABLE. I am using MS SQLServer.
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: Problem with @GeneratedValue
Similar Threads
one to one unidirectional mapping in jpa
I need help with Hibernate
hibernate one to many reationship.
ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
Hibernate - Cascading problems using ManyToOne association
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter