This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Question about mapping and persisting in Hibernate/JBoss Seam

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody. Sorry for the post so long, but I could not be shorter and sorry if this post in the wrong place, but I do not know if the problem is the mapping or is it something I'm doing wrong when I try to persist the object ... .
I have a problem to persist an object in a relation @ OneToMany. Here is the picture.
It is a module polls, where I am developing a piece of voting, involving 3 entities; Polls, Pollsoptions and Pollsvotes basically have to do the following when the User votes on a poll:
In Poll entity, update the number of votes adding +1 and update the last date of voting.
In PollsOptions entity, I have to update the number of votes received for the option that the user choose, by adding the option +1
Finally, add a record in the entity PollsVotes.

Well, I'm using JBoss Seam and did the reverse engineering of entities using JBoss Tools, and I'm using classes that JBoss Tolls generates the entities and sessions beans, I did not see anything wrong with the mapping of entities, but the problem I have is when I try to insert a record in the entity PollsOptios, the updates that I do in the other entities work without any problem.

Here's how the classes are mapped ...


Here is the method Vote I wrote to the vote, without control of this transaction, only the first steps ... and really do not know if this is correct way to do it, I tried simply adding the PollsVotes entity in the attribute pollsvoteses of the entity Polls and persist, but nothing happened, so I decided to try this approach and I am getting the following error:
nsert into polls.dbo.pollsvotes (pollsvote_date, poll_id, usr_id)
values
(?, ?, ?)
17:37:24,782 WARN [JDBCExceptionReporter] SQL Error: 515, SQLState: 23000
17:37:24,782 ERROR [JDBCExceptionReporter] Cannot insert the value NULL into column 'pollsopt_id', table 'polls.dbo.pollsvotes'; column does not allow nulls. INSERT fails.
17:37:24,783 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert: [org.domain.pollsweb.entity.Pollsvotes]

Basically he is ignoring the pv.setPollsoptions (po), which is listed in the code below.


Someone please tell me where I am wrong??

Grateful

Ronaldo.
 
    Bookmark Topic Watch Topic
  • New Topic