• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Toplink JPA insertable problem

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm pretty new to JavaEE technology. Hopefully, you guys can help me out with this issue that I'm facing.

I have a table created, which inside it there's a column "id" which is a primary key field and the key will be auto generated by default. On the other hand. I've a Entity class, where the persistence provider will auto include every field to database. My question is, how can I prevent this from happening?

By the way, I've tried using @Column(insertable=false). This doesn't seems working though.

Thanks.
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Ming Ming.

Have you played around with the @GeneratedValue annotation?

https://glassfish.dev.java.net/nonav/javaee5/api/javax/persistence/GeneratedValue.html



-Cameron McKenzie
 
ming ming
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, I've tried that, but it doesn't seem to work.
 
ming ming
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Help needed very much guys Cheers.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How is the ID generated? If it is generated by the database column (ie an identity field) then use:
 
ming ming
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I realised everytime when I use @GeneratedValue(strategy=IDENTITY), there will be an error in the .class file. It will give me something like this @GeneratedValue(strategy="<error>")

Wonder why? Is it something wrong with my netbeans compiler?
 
Gordon Yorke
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using a static import for the enum? perhaps try
 
ming ming
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Same error on the class file as well. Do I really need the @GeneratedValue(strategy=GenerationType.IDENTITY) . Since in this case, my database will automatically generate the value for me, instead of the persistence provider?

I read from the Java API docs, it says that if we have @Column(insertable=false) , the persistence provider will ignore this column for the insert statement. But for me it is not happening, every time it still insert to the column, which at the end will throw error, because of having the same primary key.
 
Gordon Yorke
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The PK must be writable or use IDENTITY sequencing. What is the error you are seeing.
 
ming ming
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This exception thrown is Follow by

This is the way, I created the table



Therefore, that's why I don't need the persistence provider to insert that column for me. Any idea?
 
Gordon Yorke
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The PK must be writable or use IDENTITY sequencing.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic