one-to-many

Recommended Table Set up for one to many/many to one situation

I need to create a script where someone will post an opening for a position, and anyone who is eligible will see the opening but anyone who is not (or opts out) will not see the opening. So two people could go to the same page and see different content, some potentially the same, some totally unique. I'm not sure the best way to arrange ...

Left outer join fetch doesn't fill map collection properly (HQL)

I've got classes with mappings like this: @Entity public class CurrencyTable { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private Long id; @Version @Column(nullable=false) private Timestamp version; @Column(length=32, unique=true) private String refCode; @OneToMany(mappedBy="currencyTab...

Custom joins entitys on Hibernate

We have a Hibernate based system with Annotations. Our entities have a custom property DELETED. We have to select non deleted entities with non deleted sub-entities. How can we can do it? Little sample for describe the situation: GenericEntity { ... @Basic @Column(name = DELETED) protected Boolean deleted = false; @...

Hibernate Unidirectional Parent/Child relationship - delete() performs update on child table instead of delete

If I delete a record from the Parent table I want the corresponding records in the child table to be deleted. How can I make Hibernate delete from the Child table rather than attempt to update with a null? I'm using Hibernate 3 but cannot use annotations at this time. I've attached copies of HBM, DAO etc below. -- Thank you in Advance...

How to map a set of objects in Hibernate without primary keys being equally named?

I have a domain object class that represents a table. This class has an association to another table, but the source class' property is not named the same as the target class' property, and I'm not sure how to hibernate map it. Here is an example of the class to have the set (one CT to many R instances): public class CT { // This ...

When to use inverse=false on NHibernate / Hibernate OneToMany relationships?

I have been trying to get to grips with Hibernate's inverse attribute, and it seems to be just one of those things that is conceptually difficult. The gist that I get is that when you have a parent entity (e.g. Parent) that has a collection of Child objects using a one-to-many mapping, setting inverse=true on the mapping tells Hibernat...

How to write the Where clause in my ObjectQuery?

Please see my code: var miportal = new AdventureWorksEntities(); // one to many relationship var result = miportal.AddressType .Include("CustomerAddress") .Where(at => at.CustomerAddress.Any(ca => ca.CustomerID == 3)); there are 2 tables; AddressType and CustomerAddress (1 CustomerAddress has...

How to tell NHibernate to map one-to-many relationship to List<T> and not IList<T>?

Hi! Can I somehow tell NHibernate to map my one-to-many relationship to a property which is of type List instead of the interface IList? I know that NHibernate uses its own IList-implementation for lazy loading, but I don't need this feature. Instead I need a class that is serializable, which I cannot accomplish by using the IList inte...

Scalable one to many table (MySQL)

I have a MySQL database, and a particular table in that database will need to be self-referencing, in a one-to-many fashion. For scalability, I need to find the most efficient solution possible. The two ways most evident to me are: 1) Add a text field to the table, and store a serialized list of primary keys there 2) Keep a linker ta...

Linq to sql: Composite foreign key in one-many relation?

Hi, I'm trying to model a database in LINQ to SQL. I have a table JournalPosts. Each entity is associated with 1 or more senders or recipients. I have the following composite primary key in my table "JournalPosts": [Column(IsPrimaryKey = true)] public int CaseYear { get; set; } [Column(IsPrimaryKey = true)] public int ...

one-to-many with criteria question

enter code hereI want to apply restrictions on the list of items, so only items from a given dates will be retrieved. Here are my mappings: <class name="MyClass" table="MyTable" mutable="false" > <cache usage="read-only"/> <id name="myId" column="myId" type="integer"/> <property name="myProp" type="...

Why won't JPA delete owned entities when the owner entity loses the reference to them?

Hi! I've got a JPA entity "Request", that owns a List of Answers (also JPA entities). Here's how it's defined in Request.java: @OneToMany(cascade= CascadeType.ALL, mappedBy="request") private List<Answer> answerList; And in Answer.java: @JoinColumn(name = "request", referencedColumnName="id") @ManyToOne(optional = false) private Req...

The correct NSPredicate format for one-to-many relationship in Core Data

Hello, I have a managed object model A and B with one-to-many relationship. For this particular task, I want to retrieve all A objects which has a relation to B with a property matches to "string". I had tried @"ALL bObjects.bProperty MATCHES 'string'", and it caused an objc_exception_throw in: [NSSQLGenerator generateSQLStatementFor...

Why does many-to-many data structure require two additional tables?

This question is based on the thread. If we have one-to-many data structure, we need to have a "help-table" to store for instance phonenumbers for one person. Many person cannot have the same phonenumbers. I look forward for an explanation why we then need two "help-tables" between many-to-many relations. An example of this is a questi...

Hibernate @OneToMany with mappedBy (parent-child) relationship and cache problem

Hi, everybody. I have this problem for a long time now, I have searched the web and SO in and out and didn't find a solution yet. I hope you can help me on that. I have a parent-child relationship between two entities like the following: @Entity public class Parent { // ... @OneToMany(mappedBy = "parent", fetch = FetchType.LA...

Does anyone use SubSonic in .Net

in SubSonic 3, if i use SimpleRepository, can i ask it to generate forkey as well include "one to many", "one to one" and "many to many" is there any sample code i can have a look at???? what i see from its demo, is only for one table, not dealing with relationship ..if it cannot deal with relationship...i won`t go into it and use it...

Hibernate one to many using something other than a primary key

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 , 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...

Sorting records in a 1:n (one-to-many) relationship

I've got 2 tables: +-----------+ +------------------------------------+--------------+ + persons | | photos | +-----------| +---------------------------------------------------+ + id | name + | id | person_id | path | title | +-----------+ +---------------------------...

How to add new object to an IList mapped as a one-to-many with NHibernate?

My model contains a class Section which has an ordered list of Statics that are part of this section. Leaving all the other properties out, the implementation of the model looks like this: public class Section { public virtual int Id { get; private set; } public virtual IList<Static> Statics { get; private set; } } public class...

Why to have a join table for 1:m relation in SQL

What is the benefit of having junction tables between the first 1:m and the second 1:m relations in the following database? The book Joe Celko's trees and hierarchies in SQL for Smarties says that the reason is to have unique relations in 1:m's. For instance, the following tables resrict users to ask the exactly same question twice an...