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

Doctrine 2 OneToMany Cascade SET NULL

You should add the option onDelete=”SET NULL” in the annotation of your entity Publication like this: class Publication { /** * @ORM\ManyToOne(targetEntity=”Teacher”, inversedBy=”publications”) * @ORM\JoinColumn(name=”teacher_id”, referencedColumnName=”id”, onDelete=”SET NULL”) */ protected $teacher; } This modification is registered in the table declaration itself. Hence, you need a database migration or a schema change for this to take … Read more

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

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.

Spring 3 MVC: one-to-many within a dynamic form (add/remove on create/update)

This point is still quite confusing and unclear on the web, so here is the way I solved my problem. This solution is probably not the most optimized one, but it works when creating and updating a master entity. Theory Use a List instead of a Set for your one-to-many relations which should be dynamically … Read more

Difference Between One-to-Many, Many-to-One and Many-to-Many?

Looks like everyone is answering One-to-many vs. Many-to-many: The difference between One-to-many, Many-to-one and Many-to-Many is: One-to-many vs Many-to-one is a matter of perspective. Unidirectional vs Bidirectional will not affect the mapping but will make difference on how you can access your data. In Many-to-one the many side will keep reference of the one side. … Read more

@OrderColumn annotation in Hibernate 3.5

The combination of @OneToMany(mappedBy=”…”) and @OrderColumn is not supported by Hibernate. This JIRA issue tracks a request to throw a more obvious error message when this invalid combination is used: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5390 I think that this isn’t supported mainly because it is an odd relational pattern. The annotations above indicate that the “one” side of the … Read more

Show a one to many relationship as 2 columns – 1 unique row (ID & comma separated list)

I believe that the answer you need is a user-defined aggregate, similar to this one: CREATE FUNCTION gc_init(dummy VARCHAR(255)) RETURNING LVARCHAR; RETURN ”; END FUNCTION; CREATE FUNCTION gc_iter(result LVARCHAR, value VARCHAR(255)) RETURNING LVARCHAR; IF result=”” THEN RETURN TRIM(value); ELSE RETURN result || ‘,’ || TRIM(value); END IF; END FUNCTION; CREATE FUNCTION gc_comb(partial1 LVARCHAR, partial2 LVARCHAR) … Read more