• 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

SQLInsert annotation and composite ids

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to use INSERT ... ON DUPLICATE KEY UPDATE feature of MySql.
The best possible way to make use of this is to add the SQLInsert annotation to the Class.

I want o insert objects of HourOfTheDay.java to the table HourOfTheDayDaily .

The columns in my table HourOfTheDayDaily are domain,year,month,date,hour,pages,hits,volume
Where domain,year,month,date,hour will form the composite primary key of the table.

My object HourOfTheDay.java has a property called name which is a reference to this composite id object. pages,hits,volume are other properties of the class itself
HourOfTheDay.name refers to ChronoStatisticalContextHour which has the properties domain,year,month,date,hour


In the ON DUPLICATE KEY UPDATE I want to change the values of pages,hits,volume in the table HourOfTheDayDaily to
pages = pages + HourOfTheDay.pages
hits= hits+ HourOfTheDay.hits
volume = volume + HourOfTheDay.volume

That is if the record with the given key already exist add the properties pages,hits,volume of the object HourOfTheDay
to the current column values columns pages,hits,volume of the table HourOfTheDayDaily



How is it possible to define this using SQLInsert annotation ?. Is it not possible via SQLInsert ?.
If not is there any way to achieve this with out writing a stored procedure.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic