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]