one-to-many

JPA / Hibernate OneToMany Mapping, using a composite PrimaryKey

僤鯓⒐⒋嵵緔 提交于 2019-11-30 03:48:22
I'm currently struggling with the right mapping annotations for a scenario using a composite Primary Key Class. First, what I am trying to achieve in words: I have 2 classes: group and FieldAccessRule. A Group can have many FieldAccessRules, while a FieldAccessRule only has ONE Group assigned. Modling this is not a problem so far (simplified): public class Group{ ... @OneToMany(mappedBy = "group") private Set<FieldAccessRule> fieldAccessRules; ... } and for the FieldAccessRule: public class FieldAccessRule { ... @ManyToOne @JoinColumn(name = "group_id") private Group group; ... } Now, I

One-to-many Flask | SQLAlchemy

橙三吉。 提交于 2019-11-30 03:38:35
问题 I am trying to create a one-to-many relationship using Flask and SQLAlchemy. I want the one-to-many relationship to be as so: "For any single movie, there can be multiple characters" Here it what I have so far, but it is saving in my DB as one-to-one right now. (One movie to one character, saving multiple times in DB for multiple characters) class Movie(db.Model): __tablename__ = "movies" id = db.Column('movies_id', db.Integer, primary_key=True) movie_type = db.Column('movie_type', db.Text())

@OneToMany mapping list size limit

巧了我就是萌 提交于 2019-11-30 01:37:27
问题 Is there any way to limit the list's size of the @OneToMany relationship in JPA? Here's my code sample: @OneToMany(mappedBy = "publication", cascade=CascadeType.PERSIST) private List<Comment> commentList; I'm using EclipseLink 2.3 JPA implementation. Thanks in advance. 回答1: Part of the Bean Validation Specification (JSR-303) is the @Size(min=, max=) annotation: Supported types are String, Collection, Map and arrays. Check if the annotated element size is between min and max (inclusive). You

Programming a one-to-many relationship

做~自己de王妃 提交于 2019-11-30 01:28:10
So I am surprised that doing a search on google and stackoverflow doesn't return more results. In OO programming (I'm using java), how do you correctly implement a one-to-many relationship? I have a class Customer and class Job . My application is for a fictious company that completes jobs for customers. My current implementation is so that the Job class doesn't have anything to do with the Customer class, there is no reference to it at all. The Customer class uses a collection and methods to hold, retrieve and modify information about the Jobs that have been assigned by and/or completed for a

Saving related records in laravel

≯℡__Kan透↙ 提交于 2019-11-29 21:18:57
I have users, and users belong to a dealership. Upon user registration, I'm trying to save a new user, and a new dealership. User database has a dealership_id column, which I want to be populated with the ID of the newly created dealership. This is my current code in the UserController store method. public function store() { $user = new User(); $user->email = Input::get('email'); $user->password = Input::get('password'); $dealership = new Dealership(); $dealership->name = Input::get('dealership_name'); $user->push(); return "User Saved"; } Trying to use $user->push(); User data gets updated,

Hibernate relation OneToMany with non unique key

回眸只為那壹抹淺笑 提交于 2019-11-29 16:56:30
I am not able to describe my problem, I try it again with example: I have two entities (tables): Department and Person . Both tables have a field CODE which is not unique . How can I define manyToMany bidirectional relations between these tables? Departmen has collection Persons which returns all entities with Person.CODE eq Department.CODE Partner has collection Departments which returns all entities with Department.CODE eq Partner.CODE I need the relation definition - no sql or hpql query. --------- Original question ------- I need to create hibernate relation one to many between Department

Select rows from one table, join most recent row from other table with one-to-many relationship

邮差的信 提交于 2019-11-29 16:49:25
What I would like to do is select a specific set of rows from one table (table A) and join with another table (table B), such that only one record will appear from table A, joined with the most recent record from table B, based on a datetime column. For example, table A has this structure (heavily simplified): id | col_1 | col_2 ---+-----------+---------------- 1 | something | something else 2 | val_1 | val_2 3 | stuff | ting 4 | goats | sheep And table B looks like this: id | fk_A | datetime_col | col_3 ---+-----------+---------------------+-------- 1 | 1 | 2012-02-01 15:42:14 | Note 1 2 | 1

Hibernate Criteria API - Filtering collection property

你。 提交于 2019-11-29 15:21:19
问题 I have such entity: @Entity public class Album { private Integer id; private Integer ownerId; private String name; private String description; private Date created; @OneToMany @JoinColumn(name = "albumId") private Set<AlbumUser> users = new HashSet<AlbumUser>(); @OneToMany @JoinColumn(name = "albumId") private Set<Picture> pictures = new HashSet<Picture>(); } and another one: @Entity public class Picture { private Integer id; private Integer creatorId; private Integer albumId; private Date

Hibernate insert cascade not inserting foreign key

吃可爱长大的小学妹 提交于 2019-11-29 14:53:01
问题 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<Tag> tags; ....... OTHER PROPERTIES ....... @Entity public class Tag ....... @Id @GeneratedValue(strategy=GenerationType.AUTO) private int id; @ManyToOne @JoinColumn(name="file_id") private File file; @Column private String tag; ....... OTHER PROPERTIES ....... I am trying to insert into

JPA Hibernate collections not lazily loaded

时间秒杀一切 提交于 2019-11-29 12:55:22
I have a JPA setup in such a way that if I do not use lazy load, almost the entire database will be loaded. I also use serializing directly on the models so sometimes I need to initialize the proxies. I only want to use lazy load on the collections. The fact that some singular entities are fetched eagerly works just fine. But no matter how I try to setup the collections I never get a collection of proxies, I always get the fully loaded collection. This is some example code: @Entity public class Thread implements Externalizable { @OneToMany(mappedBy = "parentThread", fetch = FetchType.LAZY)