Questions tagged [many-to-one]

1040 questions
6
votes
2 answers

Django model relationship to multiple models

Suppose there is an abstract model CarOwner: whereas a Person or a Business can be a CarOwner. In addition a Car with a certain VIN can belong (relate) to either a Person or a Business, but not both (mutually exclusive case). At the very end of the…
6
votes
2 answers

Symfony ManyToOne relationship getter returns empty object

I'll simplifly my code, I have te next: Doctor entity: use ...\...\Entity\Paciente; class Doctor extends Usuario { public function __construct() { ... $this->pacientes = new ArrayCollection(); …
MSánchez
  • 446
  • 1
  • 6
  • 12
5
votes
2 answers

many to one mapping Hash Function

I don't know the actual mathematical term (many to one mapping is the terminology i've used) This is my requirement: hash_code = hash_function(element 1, element 2, ...... element n) i should be able to retrieve bool b = is_valid_hash(hash_code,…
PC.
  • 6,870
  • 5
  • 36
  • 71
5
votes
1 answer

How to prevent unnecessary select on insert?

I have the following scenario (in Java / Hibernate): I have two entity classes: X and Y. X has a @ManyToOne association to Y which is not cascaded. I create an (unmanaged) instance x of X and an (unmanaged) instance y of Y, and fill the reference…
Rubrick
  • 308
  • 5
  • 13
5
votes
0 answers

Play 2.6 Ebeans relationship error

Posts Model /*set many to one relation with Privacy_Level model*/ @ManyToOne//(fetch = FetchType.LAZY) @JoinColumn(name = "privacy_level_id",referencedColumnName = "id", insertable = false, updatable = false) public Privacy_Level…
CraZyDroiD
  • 6,622
  • 30
  • 95
  • 182
5
votes
2 answers

NHibernate with mapping by code and a SQLite database: saving many-to-one parent-child entities, child gets a null foreign key

Variations of this question have been asked and answered many times and the answers have a lot of overlapping details. I have tried so many different things suggested by these answers, but none of them have worked in my case. I have a SQLite…
rory.ap
  • 34,009
  • 10
  • 83
  • 174
5
votes
2 answers

Disable Cascade in ManyToOne relationship JPA when saving

I'm having problems when saving entities in my DB. I have something like (very simplified) : @Entity public class Building { @OneToMany(mappedBy = "building", fetch = FetchType.EAGER) private List employees; } @Entity public…
jpadilladev
  • 1,756
  • 4
  • 16
  • 23
5
votes
2 answers

Hibernate @Filter on @ManyToOne

Could some please explain me why Having a @Filter on a @ManyToOne relation does not work? Here i have a really simple example showing this: I have created two simple table in my database (foo and bar) Foo: id/id_bar bar: id/name/state (state can be…
Johny19
  • 5,364
  • 14
  • 61
  • 99
5
votes
2 answers

JPA unidirectional @OneToOne vs @ManyToOne with Hibernate - no difference?

According to book Pro JPA 2 the main difference between unidirectional @ManyToOne and @OneToOne is that in @OneToOne: Only one instance of the source entity can refer to the same target entity instance. In other words, the target entity instance…
user1071076
  • 157
  • 2
  • 9
5
votes
3 answers

Many-to-one relation returns None object: SqlAlchemy

I'm trying to write Schedule class which contains records like this: ... session, base, engine declaration somewhere here... class Schedule(Base): __tablename__ = 'schedule' id = Column(Integer, primary_key=True) # and here i need ref to…
Mikhail Elizarev
  • 965
  • 3
  • 10
  • 22
5
votes
9 answers

org.hibernate.InvalidMappingException: Could not parse mapping document from resource *.hbm.xml

I know this question has been asked a lot, but I read almost every one of them but non of them helped me. I'm writing an eclipse maven project with hibernate and I'm getting this error: org.hibernate.InvalidMappingException: Could not parse mapping…
Raein Hashemi
  • 3,346
  • 4
  • 22
  • 33
5
votes
2 answers

Does Hibernate always load associated object even if it can be null?

I have a question regarding Hibernate. I have two objects with a Many-to-One relationship: Eg: Object 1: public class Person { @Basic @Column(length = 50) protected String name; @NotFound(action=NotFoundAction.IGNORE) @ManyToOne(fetch =…
rioubenson
  • 401
  • 1
  • 4
  • 16
5
votes
1 answer

M:N relationship in JPA (wrapping given tables)

I have a m:n relationship book - borrow - user, the borrow is the join table. The tables are given (can not be changed): on one side they are used by jdbc app as well. on the other side i would like to use them via jpa book(book_id) -…
cscsaba
  • 1,279
  • 3
  • 20
  • 31
4
votes
2 answers

Null foreign key, in ManyToOne relation using hibernate [4.1.1] annotations

I am trying to persist a one-to-many and a many-to-one relation using Hibernate 4.1.1 but the foreign key is always NULL. There are two entities: Account and Client. A Client could have multiple Accounts while an Account has exactly one Client. Here…
Laurențiu Onac
  • 471
  • 1
  • 7
  • 17
4
votes
1 answer

A lookup table for one-to-many relationship?

I understand that a lookup table is necessary when we are dealing with many-to-many relationship. But what about one-to-many relationship - do we need a lookup table or a foreign key in one of the tables? Another question, is one-to-many the same as…
Run
  • 54,938
  • 169
  • 450
  • 748