Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

SQLInsert annotation and composite ids  RSS feed

Anoop Krishnan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • 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 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 has a property called name which is a reference to this composite id object. pages,hits,volume are other properties of the class itself 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!