one-to-many

Hibernate - One to Many - Getters/Setters issues

大兔子大兔子 提交于 2019-12-25 06:31:00
问题 My programm is freezing when I write getters/setters for OneToMany properties. I have these two entities : COMPETENCE_LEVEL @Entity @Table(name="competence_level") public class CompetenceLevel { @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="id_competence_level") private Long idCompetenceLevel; @ManyToOne @JoinColumn(name="id_competence") private Competence competence; @ManyToOne @JoinColumn(name="id_level") private Level level; @ManyToOne @JoinColumn(name="id_profil")

How to eagerly fetch a single “default” entity from a collection in EJB3/JPA

眉间皱痕 提交于 2019-12-25 04:34:18
问题 I have a Person entity with multiple phone numbers. @OneToMany(mappedBy="person", cascade=CascadeType.ALL) public Set<PhoneNumberOfPerson> getPhoneNumbers() { return phoneNumbers; } Now I would like to implement a "get default phone number" method for Person that is eagerly fetched. This default phone number is one of the phone numbers in the phoneNumbers set. Is there any way to do this? The reason I'm trying to implement this is to have this default phone number listed on a page that lists

DataBase design: one to many database?

主宰稳场 提交于 2019-12-25 04:17:32
问题 I am very new to database designing. I have a doubt. The question is very basic. But please help me out. i will try to expain it through an example. Suppose, I got books in one table and their authors in the other(assuming that one book is written by just one author(one to many) and one author can write many books(many to one)). I am not getting how exactly to link the tables and what should be auto-incremented? tblBooks //Table 1 contains two entities { bookId // This field is auto

Doctrine2 gives me only first instance of related objects

爷,独闯天下 提交于 2019-12-25 04:05:31
问题 I am using QueryBuilder to get 10 biggest cities with states. $query = $em->createQueryBuilder() ->select('c','s') ->from('CitiesBundle:Cities', 'c') ->innerJoin('c.state', 's','WITH', 'c.state = s') ->orderBy('c.population', 'DESC') ->setMaxResults(10) ->getQuery(); generated SQL: SELECT c0_.id AS id0, c0_.name AS name1, c0_.landarea AS landarea2, c0_.density AS density3, c0_.population AS population4, s1_.id AS id5, s1_.name AS name6, c0_.state_id AS state_id7 FROM cities c0_ INNER JOIN

GORM how to ensure uniqueness of related objects property

ε祈祈猫儿з 提交于 2019-12-25 03:57:29
问题 I'm trying to get my head around GORM and relational mapping. The relationships are working fine but there is one problem. I can't seem too ensure that every MailAddress added to MailingList has a unique address. What would be the must efficient way to do this? Note: There is no unique constraint on MailAddress.address . Identical addresses can exist in the same table. class MailAddress { String name String email static belongsTo = MailingList static constraints = { name blank:true email

Does a many-to-many relationship with a recursive one-to-many in mysql require at least 4 tables?

…衆ロ難τιáo~ 提交于 2019-12-25 03:08:55
问题 I have the following relationships (Business rules): User_Company : Many-to-many (multiple companies per user, multiple users per company) Ownership : One-to-One (For each entry in relationship table, it specifies whether user is an owner or employee. If owner then a percentage must be there) Company_ownership : One-to-many for company (Recursive relationship), as another company can also be an owner in a company, percentage must be given. So ownership or a company can be made up of a number

How to avoid persisting new object when oneToMany connection?

对着背影说爱祢 提交于 2019-12-25 02:09:23
问题 There is a three lines in returnreason-table and I don't want more lines there. User just choose one of the three reasons and I want only id to rma-table. Now it inserts a new line to reason-table every time when inserting new rma. I can take relation off between the tables but I wonder if there is better solution to avoid inserting new lines when persisting rma object? If I take cascadeType off from the class Rma, it is not helping/working. Then I got an error message, that jpa found an

Modeling single child/multiple parent tables

試著忘記壹切 提交于 2019-12-25 01:16:38
问题 I'm struggling to model the relationship between multiple tables (parents) that share a single table (child). Given the following parent 1 table (the other parent tables 2,3 and so on are similar): @Entity @Table (name="parent1") public class ParentEntity1 { @Id @Column(name="id") @GeneratedValue(strategy=GenerationType.IDENTITY) private Integer id; // relationship with child table @OneToMany(mappedBy = "parentId", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)

Sails 1.0 cannot access autogenerated associated entity routes

孤者浪人 提交于 2019-12-25 00:54:33
问题 I have an association between Client and Budget as follows: //Client.js module.exports = { primaryKey: 'id', attributes: { id: { type: 'number', unique: true, autoIncrement: true }, name: { type: 'string' }, phone: { type: 'string', unique: true }, email: { type: 'string', unique: true }, budgets: { collection: 'budget', via: 'client' }, } }; // Budget.js module.exports = { primaryKey: 'id', attributes: { id: { type: 'number', unique: true, autoIncrement: true }, client: { model: 'client' },

What exactly does mappedby in hibernate mean?

邮差的信 提交于 2019-12-25 00:25:35
问题 I tried the documentation but I've got nothing. I tried searching for it on google and stackoverflow but there is still no help. I've got a singleton class and this class has a onetomany relationship to another class. Here's my code. @Entity public class HomeLibrary extends BaseModelObject { @OneToMany(mappedBy = "homeLibrary", cascade = { CascadeType.ALL }) private Collection<Book> books = new ArrayList<Book>(); private static HomeLibrary sharedHomeLibrary = new HomeLibrary(); public static