Sequel accessing many_to_many join table when adding association
The recommended way to do this is to add a model for the join table. However, if you don't want to do that, you can do:
class Wishlist
def _add_item(item, hash={})
model.db[:items_wishlists].insert(hash.merge(:item_id=>item.id, :wishlist_id=>id))
end
end
Hibernate JPA No join table created on ManyToMany association
You're mixing field and accessor use for your mapping annotations. You can't do that. In any given class, mapping annotations must be either all on the getters or all on the fields. If you try to mix them, some on the getters and some on the fields, Hibernate will pick getters or fields and ignore the other (I'm not sure if its specified how Hibernate chooses if you don't specify).
Your @Id
annotation in each class is on a getter, and that's making Hibernate use your getter-based annotations. Either move the @Id
and @GeneratedValue
annotations to the id
field in each class, or define a getter (and setter) for the actor/film relationship and move the @ManyToMany
and @JoinTable
annotations to the new getter.
With the annotations on the fields, Hibernate will bypass your getters/setters and access the entity internal fields directly. With them on the getters, Hibernate will call your getters and setters.
Many to many association without join table
JPA does not allow this as it requires foreign keys to reference the full primary key for identity purposes, and it might not work well with caching. If you can, I would recommend switching to a more traditional model using a relation table that uses the actual primary keys.
If your provider allows mapping partial pks (I believe Hibernate does), what you would do is make two 1:M mappings each using a JoinColumn instead of JoinTable, but mark the one on Node->Authority as insertable=false, updatable=false
For example, something like:
public class Node {
@Id
private Integer id;
private String nameNode;
@OneToMany
@JoinColumn(name = "idAuthorites", referencedColumnName = "idAuthorites", insertable=false, updatable=false)
private Set<Authority> authorities;
...
public class Authority {
@Id
private AuthorityPK pk;
private String person;
@OneToMany
@JoinColumn(name = "idAuthorites", referencedColumnName = "idAuthorites")
private Set<Node> nodes;
...
Hibernate many-to-many association not updating join table
How about using merge? That is what you are cascading after all and you have modified a detached object and need to merge back the changes:
public void update(User user) {
dao.merge(user);
}
EDIT: for clarity this replaces the old update method, so it should be called from the client side with loggedInUser, just like before.
EDIT 2: as noted in the comments merge will update all fields. The old update method also seems to do that? Optimistic locks (version numbers) can be used to guard against overwriting other changes by mistake.
Related Topics
Connecting to Oracle Db Using Ruby
How to Calculate 32 Bit Crc in Ruby on Rails
Use Separate Authentication Model with Devise on Rails
Dynamically Generate Scopes in Rails Models
Ruby - Difference Between :Variable and @Variable
Set Tag Attribute and Add Plain Text Content to the Tag Using Nokogiri Builder (Ruby)
Set Default Stage with Capistrano 3
Rails First_Or_Create Activerecord Method
Ruby: Remove Whitespace Chars at the Beginning of a String
Why Don't Ruby Methods Have Lexical Scope
Rspec View Undefined Method Stub_Model
Perform One Validation Only If All Other Validations Pass
Convert 12 Hr Time to 24 Hr Format in Ruby
After Installing a Gem Within a Script, How to Load the Gem
How to Write a JSON Schema for Array of Objects
Installing Nokogiri MAC Os X 10.8.2 Xcode Installed
How to Connect to Postgresql Database After Upgrading to Yosemite 10.10