one-to-many

Using a List in a where clause in Entity Framework

∥☆過路亽.° 提交于 2019-12-23 21:22:16
问题 I am trying to retrieve document id's over a one-to-many table. I want to use a List in the where clause to find all id's that are connected with every element in the list. List<int> docIds = (from d in doc where _tags.Contains(d.Tags) select d.id).ToList<int>(); I know that the contains must be incorrect but I can't work it out. If I try a foreach I can't work out how to check if the document contains all Tags. 回答1: If you want that all d.Tags should be in the included in the _tags list, you

PHP and outputting one-to-many results

三世轮回 提交于 2019-12-23 21:09:48
问题 I've only dealt with one-to-one relationships in php so far, but I'm stuck on a problem which involves a one-to-many relationship. I've been sitting on this for a few days with no luck, so I'm desperate for someone to step in and show me a solution before I lose my mind. In my database have a series of urls, which are received by a SELECT query along with various other fields, from different tables. Every url has at least one category associated with it, but can have multiple categories. So

one to many unidirectional hibernate mapping doesn't save the child table

∥☆過路亽.° 提交于 2019-12-23 17:45:03
问题 I have two tables called Person and Address . These tables I mapped one to many with hibernate using annotation. Then in my parent entity Person I create a Set<Address> to hold the child class. After that I create a set of address and set to Person entity and also set Person's own values. My problem is that when I am save the parent entity child does not save in DB. Here is my code: Person.java @Entity @Table(name="PERSON") public class Person { @Id @GeneratedValue(strategy = GenerationType

Hibernate one to many using something other than a primary key

好久不见. 提交于 2019-12-23 09:42:19
问题 I have a class A that has a set of B 's. However, these two objects are linked by fields that are NOT the primary key. For B , I can use <key column> , but how do I specify that the join should be in A . secondary_column ? Not A . table_primary_key_id ? <class table="a"> <id column="table_primary_key_id"> </id> <property column="secondary_column" /> <set table="B" lazy="false" > <key column="B_not_primary" /> <one-to-many class="BClass" /> </set> </class> 回答1: Solved with <set name="someSet"

Entity Framework one-to-many with table-per-hierarchy creates one foreign key column per subclass

时光总嘲笑我的痴心妄想 提交于 2019-12-23 07:25:00
问题 I have a Garage which contains Cars and Motorcycles . Cars and motorcycles are Vehicles . Here they are: public class Garage { public int Id { get; set; } public virtual List<Car> Cars { get; set; } public virtual List<Motorcycle> Motorcycles { get; set; } public Garage() { Cars = new List<Car>(); Motorcycles = new List<Motorcycle>(); } } public abstract class Vehicle { public int Id { get; set; } public string Make { get; set; } public string Model { get; set; } } public class Car : Vehicle

Entity Framework one-to-many with table-per-hierarchy creates one foreign key column per subclass

二次信任 提交于 2019-12-23 07:24:56
问题 I have a Garage which contains Cars and Motorcycles . Cars and motorcycles are Vehicles . Here they are: public class Garage { public int Id { get; set; } public virtual List<Car> Cars { get; set; } public virtual List<Motorcycle> Motorcycles { get; set; } public Garage() { Cars = new List<Car>(); Motorcycles = new List<Motorcycle>(); } } public abstract class Vehicle { public int Id { get; set; } public string Make { get; set; } public string Model { get; set; } } public class Car : Vehicle

Hibernate One To Many Eager Not Pulling in all Data

孤人 提交于 2019-12-23 04:45:29
问题 I am doing an eager load on a one to many relationship in hibernate. The parent items are pulled back correctly but they only recieve one item each in their child list. One of the parent's should have two. I run the query Eclipse spits out, and it pulls the correct results. Question is why would only one item go into each list when one should have two? @OneToMany(mappedBy="badge", fetch=FetchType.EAGER) public List<BadgeLevel> getBadgeLevels() { return this.badgelevels; } SQL select * from (

One-To-Many Count

浪尽此生 提交于 2019-12-22 10:17:05
问题 I wonder if this can be resolved with less overhead: Given a simple one-to-many relationship Product --> Size (Product has got one size). In order to figure out how many products are assigned to a size I would update the mapping of Size with a Product- Bag . But what if I am only interested in the count (no need for any product details), can this be done without the overhead of loading all the product-objects? Thx for any tipps sl3dg3 回答1: Use attribute lazy="extra" in hbm or ExtraLazyLoad()

How to apply a default-restriction on Entity-Bean @OneToMany Relationships

大城市里の小女人 提交于 2019-12-22 10:05:52
问题 I have two entity models, Customer and Order. Each customer could have thousands of orders. I have a OneToMany and ManyToOne relationship between these two entities. How do I restrict this relationship's list to only top 10 orders? Is it possible to apply 'WHERE' condition as an attribute on @OneToMany or not? Like: @OneToMany("Where Order.orderNo > 100") My problem is when the object created by Entity Manager all Orders are created in memory. Lazy loading can not solve my consideration,

Hibernate, Persistence and @OneToMany and @ManyToOne annotations problems

烈酒焚心 提交于 2019-12-22 09:22:03
问题 I have some problem with @OneToMany and @ManyToOne annotations. I have two class Suite and SuiteVersion. A SuiteVersion is dependent of a suite. So i have implemented this in my code: Class Suite : @OneToMany(mappedBy = "suite") @Cascade(CascadeType.DELETE_ORPHAN) private List<SuiteVersion> listSuiteVersion = new ArrayList<SuiteVersion>(); Class SuiteVersion : @ManyToOne() @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE}) private Suite suite; But i have some problem when i delete