• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate annotations in POJO s ..

 
pavani potnuru
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using hibernate annotations in my POJOs for mapping..
I have two pojos named category and recommendation which has one to many relationship..
Category POJO::

@OneToMany(mappedBy = "category")
// pointing Recommendation's category field
@Column(name = "rec_id")
// inverse=true
private List<Recommendation> recomList;

and getter setter methods..

Recommendation POJO:::

@Id
@Column( length = 9, nullable = false, name = "rec_id" ,unique=true)
@GeneratedValue(strategy = GenerationType.AUTO)
private Long recID ;

@ManyToOne
@JoinColumn( nullable = false,name="category_id") // inverse = false
private Category category;


and getter setter methods..

When I am trying to save a recommendation I am getting an
exception

I have set all the values needed for recommendation and set all the values needed for category..

I think the problem is with mapping .. Can anyone please tell me if my mapping is wrong or i have to add any other annotations..

Exception:::

DataIntegrityViolationException: not-null property references a null or transient value:
com.common.hibernate.Recommendation.category; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value:

Please help me out if you have any idea
 
Rodrigo Lopes
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exception message says that the category attribute of the recommendation is null.
Did you set the category of the recommendation before saving it?
 
Reehan Lalkhanwar
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think in the mapping the @ManyToOne part might not be correct.
I was told here that there is no many-to-one.
 
Rodrigo Lopes
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There was some mis-understanding there...
There IS @ManyToOne

Edited to include the URL
[ June 05, 2008: Message edited by: Rodrigo Lopes ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Reehan Lalkhan:
I think in the mapping the @ManyToOne part might not be correct.
I was told here that there is no many-to-one.


I think you mis-interpreted the statement made there. It was just someone talking about Employees to Departments in terms of a made up real life situation, and not specifically about mappings.

Like in real life there might be a case of

One Employee to Many departments, although that would infer that the company only had One employee, or that only one person could be in a department at one time.

Not that there isn't a Many To One mapping.



Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic