Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Paul Clapham
Ron McLeod
Jeanne Boyarsky
Tim Cooke
Sheriffs:
Bear Bibeault
Henry Wong
Devaka Cooray
Saloon Keepers:
salvin francis
Tim Moores
Tim Holloway
Stephan van Hulst
Frits Walraven
Bartenders:
Jj Roberts
Carey Brown
Scott Selikoff
Forum:
Object Relational Mapping
Problem with @GeneratedValue
Deepa Datar
Greenhorn
Posts: 4
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 4
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 4
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Its working now. I changed the GenerationType from AUTO to TABLE. I am using MS SQLServer.
I didn't say it. I'm just telling you what this tiny ad said.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Hibernate - Cascading problems using ManyToOne association
hibernate one to many reationship.
I need help with Hibernate
one to one unidirectional mapping in jpa
ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
More...