many-to-many

Determining ManyToMany vs OneToMany using ClassMetadata

眉间皱痕 提交于 2019-12-06 06:37:58
问题 I am using ClassMetadata to determine the structure of a hibernate POJO. I need to determine if a collection is OneToMany or ManyToMany. Where is this information? Can I get to it without using reflection? See my code below. //Get the class' metadata ClassMetadata cmd=sf.getClassMetadata(o.getClass()); for(String propertyName:cmd.getPropertyNames()){ if (cmd.getPropertyType(propertyName).isCollectionType() && cmd.??()) //Do something with @ManyToMany collections. } All I need is method to

How to cascade persist only new entities

爱⌒轻易说出口 提交于 2019-12-06 06:14:05
问题 I'm having trouble figuring out how to set up JPA persistence (using EclipseLink and transaction-type="RESOURCE_LOCAL") correctly for the following entities: @Entity public class User { // snip various members @ManyToMany private List<Company> companies; public void setCompanies(List<Company> companies) { this.companies = companies; } } @Entity public class Company { // snip various members } What I'm trying to do is set up a cascade for the companies list so that, if a new Company that hasn

Problem with SaveChanges() Entity Framework 4.1

懵懂的女人 提交于 2019-12-06 06:01:52
I am having problem with saving the changes to database. I am updating the model A in my controller, however when I save the changes using SaveChanges() I end up having a duplicated item in database for B. After the UpdateModel() is called I inspected the Bs property and it was as I expected however right after the SaveChanges() is called if I inspect the Bs property I will see that the Id is completely different (new Id and new entry). My class is similar to this: public class A { [HiddenInput(DisplayValue = false)] public int AId { get; set; } public string Name { get; set; } public virtual

Rails create form for model with many to many relation

邮差的信 提交于 2019-12-06 05:52:43
问题 I have two models, Recipe and Tag , with a has_and_belongs_to_many relation. For this relation I have a simple join table, RecipesTags . Recipe: has_and_belongs_to_many :tags Tag: has_and_belongs_to_many :recipes Now upon creating a new recipe, the user gets to fill in which category the recipe belongs to in forms of checkboxes, like "Meat", "Fish", and so on. These categories are in fact just tags in the database. Problem: the recipes doesn't get any tags saved to it. Recipe new and create

ON CASCADE DELETE on JPA2 many-to-many relationship

南楼画角 提交于 2019-12-06 05:38:35
问题 I have read a lot of topics regarding cascading and many-to-many associations, but I haven't been able to find an answer to my particular question. I have a many-to-many relationship between UserProfiles and Roles. When I remove a UserProfile I want the associated records in the join table (userprofile2role) to be removed by the database, so with an actual SQL 'ON DELETE CASCADE' action. Is this possible? Whatever I try, Hibernate always creates the UserProfile table without specifying ON

Rails nested form on many-to-many: how to prevent duplicates?

旧街凉风 提交于 2019-12-06 05:33:57
I've setup a nested form in my rails 3.2.3 app, it's working fine, my models are: class Recipe < ActiveRecord::Base attr_accessible :title, :description, :excerpt, :date, :ingredient_lines_attributes has_and_belongs_to_many :ingredient_lines accepts_nested_attributes_for :ingredient_lines end and: class IngredientLine < ActiveRecord::Base attr_accessible :ingredient_id, :measurement_unit_id, :quantity has_and_belongs_to_many :recipes belongs_to :measurement_unit belongs_to :ingredient end As above, a Recipe can have multiple IngredientLines and vice versa. What I'm trying to avoid is record

SQL Query for exact match in many to many relation

◇◆丶佛笑我妖孽 提交于 2019-12-06 05:33:53
I have the following tables(only listing the required attributes) medicine (id, name), generic (id, name), med_gen (med_id references medicine(id),gen_id references generic(id), potency) Sample Data medicine (1, 'Crocin') (2, 'Stamlo') (3, 'NT Kuf') generic (1, 'Hexachlorodine') (2, 'Methyl Benzoate') med_gen (1, 1, '100mg') (1, 2, '50ml') (2, 1, '100mg') (2, 2, '60ml') (3, 1, '100mg') (3, 2, '50ml') I want all the medicines which are equivalent to a given medicine. Those medicines are equivalent to each other that have same generic as well as same potency. In the above sample data, all the

django-nonrel on Google App Engine - Implications of using ListField for ManyToMany

僤鯓⒐⒋嵵緔 提交于 2019-12-06 04:49:47
I am working on a Google App Engine application and I am relatively new at this. I have built an app already in Django and have a model using a field type of ManyToMany. I am aware that django-nonrel does not support many-to-many field types of Django. So I am considering using ListField instead. Questions: - What is the implication of using ListField instead of ManyToMany? - I am aware that this means that Django's JOIN API cannot be used. But what does this mean for my app? - Am I going to have problems when it comes to doing a search for something in a many-to-many field? Apologies if these

Copy datasets with n:m-relation

ぃ、小莉子 提交于 2019-12-06 04:11:15
I would like to use the single SQL-statement insert into T (...) select ... from T where ... to copy a lot of datasets. My problem is that there are N:M-relationships from table T to other tables and these have to be copied too. How can I do this, if I do not know which original dataset belongs to which copied dataset? Let me demonstrate by example. Content of the database before: Table T : ID | COL1 | COL2 ----------------- 1 | A | B 2 | C | D N:M-table references table U from table T (table U is not shown): T | U --------- 1 | 100 1 | 101 2 | 100 2 | 102 My copy operation where [???] is the

Django model with Foreign Key and ManyToMany relations to same model

偶尔善良 提交于 2019-12-06 03:17:22
问题 I have a django model as follows: class Subscription(models.Model): Transaction = models.ManyToManyField(Transaction, blank=True, null=True) User = models.ForeignKey(User) ...etc... I am trying to add a ManyToMany field to the User model as follows: SubUsers = models.ManyToManyField(User, blank=True, null=True) but I get this error when I run syncdb: AssertionError: ManyToManyField(<django.db.models.fields.related.ForeignKey object at 0x19ddfd0>) is invalid. First parameter to ManyToManyField