-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Help with list one-to-many <-> many-to-one
PostPosted: Wed Feb 08, 2006 12:49 pm 
Newbie

Joined: Wed Feb 08, 2006 12:29 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1.1

Annotations: 3.1beta8

[b]Mapping documents:

none

Code between sessionFactory.openSession() and session.close():


Full stack trace of any exception that occurs:
Hibernate: update USER_SEARCHENGINE set user_id=null, user_index=null where user_id=?
WARN - JDBCExceptionReporter - SQL Error: 0, SQLState: null
ERROR - JDBCExceptionReporter - Batch entry 0 update USER_SEARCHENGINE set user_id=null, user_index=null where user_id=50 was aborted. Call getNextException to see the cause.
WARN - JDBCExceptionReporter - SQL Error: 0, SQLState: 23502
ERROR - JDBCExceptionReporter - ERROR: null value in column "user_id" violates not-null constraint
ERROR - tractFlushingEventListener - Could not synchronize database state with session

Name and version of the database you are using:
postgresql 8.1

The generated SQL (show_sql=true):
update USER_SEARCHENGINE set user_id=null, user_index=null where user_id=?


I'm trying to create a one-to-many many-to-one mapping similar to CategorizedItem in caveat emptor.

User --- otm ---> UserSearchengine <--- mto --- Searchengine

The only difference is that i need one side to be a list (User):

The mapping in User:
Code:
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@JoinColumn(name="user_id")
@IndexColumn(name="user_index")
private List<UserSearchengine> userSearchengines = new ArrayList<UserSearchengine>();



The relevant part of UserSearchengine
Code:
@Embeddable
public static class UserSearchengineId implements Serializable {
       @Column(name="user_id")
             private Long userId;
[...]

@EmbeddedId
private UserSearchengineId id = new UserSearchengineId();


@ManyToOne
@JoinColumn(name="user_id", insertable = false, updatable = false)
private User user;

[...]


And Searchengine:
Code:
@OneToMany
@JoinColumn(name = "searchengine_id")
private Set<UserSearchengine> userSearchengines = new HashSet<UserSearchengine>();



When i delete a UserSearchengine from user like: user.getUserSearchengines().remove(0) it throws a not-null constraint exception.
I've tried using mappedBy="user" in the User class but that makes the user_index column empty.

Thanks for any help!



[/code]


Top
 Profile  
 
 Post subject: Anyone?
PostPosted: Thu Feb 09, 2006 4:10 am 
Newbie

Joined: Wed Feb 08, 2006 12:29 pm
Posts: 2
I've not found any solution for this. Any hint would be helpful?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.