• 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

Saving database records problem

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 3 tables (MySQL). Invoice, product and JoinTable InvoiceItems.
When I have new Invoice, I select one ore more products from Product table.
I need insert one row in Invoice table and one or more rows in InvoiceItems table. Product table not change.
I geting error that column 'idinvoice' cannot be null. Can somebody help me please please please.
You may see picture of tables relationship below (attachment).







Backing bean part



Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'idinvoice' cannot be null
Error Code: 1048
Call: INSERT INTO fakstavke_u (CenaStr, trosakproc, mpc, Nabavna, pdv, Kolicina, vpc, marza, Rabat, trosak, marzaproc, Cena, idproduct, idinvoice) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [1.0, 0.0, 450.0, 450.0, 18, 1.0, 450.0, 0.0, 0.0, 0.0, 0.0, 450.0, null, null]
Query: InsertObjectQuery(entity.InvoiceItems[invoiceItemsUPK=null])
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
*
*
tritabele2.JPG
[Thumbnail for tritabele2.JPG]
3 tables relationship picture
 
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The column "idinvoice" has been declared with the constraint "Not Null" in DB.

And you have given the annotation



"insertable=false" which stops to insert the value into the "idinvoice" column... So, the INSERT Query is constructed with "NULL" value to be inserted into that column...

Due to the "Not Null" constraint, you are getting such error... make it as "insertable=true" or remove that[ by default insertable is true]
 
Milutin Markovic
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have error in my queston. Idproduct cannot be null but I understood you and fix that. Thanks thanks thanks.

But when idproduct column is insertable=true I get error that column specified twice. Same with column idinvoice.

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Column 'idproduct' specified twice
Error Code: 1110
Call: INSERT INTO invoiceItems (CenaStr, trosakproc, mpc, Nabavna, pdv, Kolicina, vpc, marza, Rabat, trosak, marzaproc, Cena, idproduct, idproduct, idinvoice, idinvoice) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [1.0, 0.0, 470.0, 470.0, 18, 1.0, 470.0, 0.0, 0.0, 0.0, 0.0, 470.0, null, null, null, null]
Query: InsertObjectQuery(entity.invoiceItems[invoiceItemsUPK=null])

Why have duplicate column? I will try to solve that tomorow. I am glad that I rid of error 1048 that troubling me two days.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic