Questions tagged [many-to-one]

1040 questions
17
votes
3 answers

JPA Composite key with ManyToOne getting org.hibernate.PropertyAccessException: could not set a field value by reflection setter of

I have a composite key ContractServiceLocationPK made out of three id's (contractId, locationId, serviceId) of type long in an embeddable class. The class which uses this composite key, ContractServiceLocation, maps these ids, using @MapsId…
MrPlow
  • 1,295
  • 3
  • 26
  • 45
16
votes
3 answers

Doctrine: Is it possible to INDEX BY a related field?

I have a Doctrine model (Assignment), which has a many-to-one relationship with another model (Region). Assignments are owned by users (with each user having only one assignment per region at a time), and I am trying to use indexBy to have the…
LeafStorm
  • 3,057
  • 4
  • 24
  • 28
14
votes
6 answers

JPA: BeanCreationException: OneToMany & ManyToOne mapping JPA / Hibernate

I have two tables with foreign key relations. I've tried searching on how to do it and it always leads to OneToMany & ManyToOne mapping. I have these two tables. user_role user I'm trying to display all the users and show their position by getting…
12
votes
1 answer

How to create a composite primary key which contains a @ManyToOne attribute as an @EmbeddedId in JPA?

I'm asking and answering my own question, but i'm not assuming i have the best answer. If you have a better one, please post it! Related questions: How to set a backreference from an @EmbeddedId in JPA hibernate mapping where embeddedid (?) JPA…
Tom Anderson
  • 46,189
  • 17
  • 92
  • 133
12
votes
2 answers

Hibernate ManyToOne with FetchType.LAZY not fetching lazy

I am using Hibernate with spring. I have a model-class like this. @Entity @Table(name = "forumtopic") public final class Forumtopic extends AbstractUserTracking implements java.io.Serializable { /**SNIP **/ private Forumcategory…
KarlsFriend
  • 745
  • 1
  • 4
  • 17
11
votes
1 answer

Doctrine OneToMany relationship error

I am trying to set up some ManyToOne/OneToMany relationships on objects in my database using Doctrine (2.2.3+) via Symfony2 (2.3.0) and am getting a strange error. Here are the relevant parts of the objects (many attributes to one product): /** *…
Aaron Luman
  • 635
  • 1
  • 10
  • 29
10
votes
2 answers

Doctrine 2 ManyToOne with multiple joinColumns

I'm trying to select the matching row in the product_item_sortorder table based on a productId and toolboxItemId from the product_item table. In normal SQL that would be for a given productId: SELECT pi.*, pis.* FROM product_item pi LEFT JOIN…
tom
  • 8,189
  • 12
  • 51
  • 70
10
votes
3 answers

Hibernate two ManyToOne relations on one Table, the first gets Eager and the second LAZY loaded

I have got the following Entities, an item which can has up to two categories, a primary and a secondary. Both categories are mapped ManyToOne to the category table using a JoinColumnsOrFormulas. The first one gets fetched EAGER as expected, but the…
Guido Krömer
  • 477
  • 1
  • 6
  • 14
10
votes
2 answers

Hibernate insert cascade not inserting foreign key

I have two entities: @Entity public class File ....... @Id @GeneratedValue(strategy=GenerationType.AUTO) private int id; @OneToMany(fetch=FetchType.LAZY, mappedBy="file", cascade=CascadeType.ALL) private List tags; ....... OTHER…
El Guapo
  • 5,581
  • 7
  • 54
  • 82
10
votes
2 answers

Hibernate annotated many-to-one not adding child to parent Collection

I have the following annotated Hibernate entity classes: @Entity public class Cat { @Column(name = "ID") @GeneratedValue(strategy = GenerationType.AUTO) @Id private Long id; @OneToMany(mappedBy = "cat", cascade = CascadeType.ALL, fetch…
Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
10
votes
2 answers

JPA @OneToMany and composite PK

I am working on a JPA project. I need to use a @OneToMany mapping on a class that has three primary keys. You can find the errors and the classes after this. javax.persistence.PersistenceException: No Persistence provider for EntityManager named…
Fleuri F
  • 223
  • 1
  • 2
  • 9
10
votes
2 answers

Hibernate @ManyToOne only works with CascadeType.ALL

I am using Hibernate 3.3.1 and i would like to create a relation between persons and an assigned company. They should be loosely coupled, but i would like to arrange to create a company via cascade and not explicitly calling…
Shannon
  • 731
  • 3
  • 12
  • 26
10
votes
10 answers

How to remove Create and Edit... from many2one field.?

Please advice me How to remove "Create and Edit..." from many2one field.? that item shows below in the many2one fields which I filtered with domain option. OpenERP version 7
Anne Mary
  • 319
  • 2
  • 4
  • 17
9
votes
2 answers

Construct JPA query for a OneToMany relation

I've those 2 entities Class A { @OneToMany(mappedBy="a") private List bs; } Class B { @ManyToOne private A a; private String name; } 1) I would like to construct a query that says get all A's that have at least one B with…
mohamede1945
  • 7,092
  • 6
  • 47
  • 61
9
votes
2 answers

Symfony2 / Doctrine2 - ManyToOne - Save inverse side

I am new to Symfony and Doctrine. I have an entity "User" and an entity "Type". One user can have one favorite type and one type can have many users that have that specific type as favorite. So I need a Many (User) to One (Type) relationship. I…
Simon Hessner
  • 1,757
  • 1
  • 22
  • 49
1
2
3
69 70