NHibernate configuration for uni-directional one-to-many relation

NH3 and above allow to correct save entities in case of uni-directional one-to-many mapping without annoying save null–save–update cycle, if you set both not-null=”true” on <key> and inverse=”false” on <one-to-many> FluentNHibernate code snippet for that: public class MasterMap : ClassMap<Master> { public MasterMap() { Id(x => x.MasterId); Map(x => x.Name); HasMany(x => x.Details) .Not.Inverse() //these … Read more

Hibernate inserts duplicates into a @OneToMany collection

It’s a bug in Hibernate. Surprisingly, it’s not reported yet, feel free to report it. Operations against non-initialized lazy collections are queued in order to execute them after collection is initialized, and Hibernate doesn’t handle the situation when these operations conflict with the data from the database. Usually it’s not a problem, because this queue … Read more

Hibernate unidirectional one to many association – why is a join table better?

Consider the situation where the owned entity type can also be owned by another parent entity type. Do you put foreign key references in the owned table to both parent tables? What if you have three parent types? It just doesn’t scale to large designs. A join-table decouples the join, so that the owned table … Read more

AttributeError: ‘int’ object has no attribute ‘_sa_instance_state’

the problem is this: post = Post(body=form.body.data, timestamp=datetime.utcnow(), thread=thread.id, author=g.user.id) you want to work with ORM objects, not primary key columns: post = Post(body=form.body.data, timestamp=datetime.utcnow(), thread=thread, author=g.user) the error means that an integer is being interpreted as an ORM object.

Deleted object would be re-saved by cascade (remove deleted object from associations)

The solution is to do exactly what the exception message tells you: Caused by: org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations) Remove the deleted object from an associations (sets, lists, or maps) that it is in. In particular, i suspect, from PlayList.PlaylistadMaps. It’s not enough to just delete the … Read more

JPA OneToMany and ManyToOne throw: Repeated column in mapping for entity column (should be mapped with insert=”false” update=”false”)

I am not really sure about your question (the meaning of “empty table” etc, or how mappedBy and JoinColumn were not working). I think you were trying to do a bi-directional relationships. First, you need to decide which side “owns” the relationship. Hibernate is going to setup the relationship base on that side. For example, … Read more