one-to-many

Delete child in one-to-many relation throws ObjectDeletedException

泄露秘密 提交于 2019-12-04 04:02:31
I just don't understand why Hibernate throws exception mentioned in title. I probably don't understand state management idea behind Hibernate. I have following situation: One-to-many relation between Organization and Employee Organization.hmb.xml <set name="employees" inverse="true" cascade="save-update"> <key column="organization_id"/> <one-to-many class="Employee"/> </set> Employee.hbm.xml <many-to-one name="organization" class="Organization" column="organization_id" /> I use standard Spring/Hibernate app architecture with Services and DAOs, where DAOs extend HibernateDaoSupport class and

JPA one-to-many filtering

陌路散爱 提交于 2019-12-03 23:22:57
We are nesting several entities. However upon retrieving we only want to get those entities which are active. @Entity public class System { @Id @Column(name = "ID") private Integer id; @OneToMany(mappedBy = "system") private Set<Systemproperty> systempropertys; } @Entity public class Systemproperty { @Id @Column(name = "ID") private Integer id; @Id @Column(name = "ACTIVE") private Integer active; } When requesting the Systemproperties I only want to get the properties that are active ( active = 1 ). Searching around I found some hibernate annotations and the possibility to use subqueries .

NHibernate many-to-many assocations making both ends as a parent by using a relationship entity in the Domain Model

左心房为你撑大大i 提交于 2019-12-03 22:47:50
Entities: Team <-> TeamEmployee <-> Employee Requirements: A Team and an Employee can exist without its counterpart. In the Team-TeamEmployee relation the Team is responsible (parent) [using later a TeamRepository]. In the Employee-TeamEmployee relation the Employee is responsible (parent) [using later an EmployeeRepository]. Duplicates are not allowed. Deleting a Team deletes all Employees in the Team, if the Employee is not in another Team. Deleting an Employee deletes only a Team, if the Team does not contain no more Employees. Mapping: public class TeamMap : ClassMap<Team> { public TeamMap

Populating an object based on a one-to-many table relationship in SQL

感情迁移 提交于 2019-12-03 21:29:19
问题 I have an object in C# like this: private ClassWidget { public int ID; public List<int> WidgetFavoriteNumbers; } Let's say I have two tables in SQL, one defines widget properties, and the other holds many records for a single widget, let's say the widget's favorite numbers: widgets ----------- id (int, not null) // other properties ... widget_nums ---------- widget_id (int, not null) num (int) I find myself frequently executing two SQL queries to populate this object even though I know I can

PHP and MySQL - efficiently handling multiple one to many relationships

♀尐吖头ヾ 提交于 2019-12-03 20:51:13
I am seeking some advice on the best way to retrieve and display my data using MySQL and PHP. I have 3 tables, all 1 to many relationships as follows: Each SCHEDULE has many OVERRIDES and each override has many LOCATIONS . I would like to retrieve this data so that it can all be displayed on a single PHP page e.g. list out my SCHEDULES. Within each schedule list the OVERRIDES, and within each override list the LOCATIONS. Option1 - Is the best way to do this make 3 separate SQL queries and then write these to a PHP object? I could then iterate through each array and check for a match on the

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

痴心易碎 提交于 2019-12-03 20:12:16
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 are the classes (only what matters): Account.java @Entity @Table(name = "account") public class Account implements Serializable { private Client client; @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") public long getId() { return id; } @ManyToOne @JoinColumn(name = "id_client") public Client getClient() { return client;

One-To-Many relationship in ORMLite Android

混江龙づ霸主 提交于 2019-12-03 17:31:25
问题 How do I implement one-many relationship in ORMLite Android? please find the example public class A { private String name; @DatabaseField (foreign = true, foreignAutoRefresh = true, columnName = "A") private B b; @DatabaseField(columnName = "author") private String authorName; } public class B { @DatabaseField(generatedId = true, columnName = "id") private long id; @DatabaseField(columnName = "name") private String name; @ForeignCollectionField Collection<A> aees; } B has collection of A. I

spring rest lazy loading with hibernate

南楼画角 提交于 2019-12-03 17:17:29
I am trying to develop spring rest api with hibernate. after searching in google, I have not find solution to lazy loading. I have two entity like below: University.java @Entity() @Table(schema = "core", name = "university") public class University extends BaseEntity { private String uniName; private String uniTelephon; @LazyCollection(LazyCollectionOption.FALSE) @OneToMany(fetch = FetchType.LAZY, mappedBy = "university", cascade = CascadeType.ALL) @JsonManagedReference private List<Student> students; //setter and getter } Student.java @Entity @Table(schema = "core",name = "student") public

How do I handle table relationships with the repository pattern?

◇◆丶佛笑我妖孽 提交于 2019-12-03 16:34:08
问题 I'm implementing the repository pattern as part of an ASP.NET MVC site. Most examples I've seen of repositories are fairly simple. For example here's a typical abstract repository interface. public interface IRepository<TEntity> { IQueryable<TEntity> All(); TEntity FindBy(int id); TEntity FindBy(Expression<Func<TEntity, bool>> expression); IQueryable<TEntity> FilterBy(Expression<Func<TEntity, bool>> expression); bool Add(TEntity entity); bool Update(TEntity entity); bool Delete(TEntity entity

Symfony2: Warning: spl_object_hash() expects parameter 1 to be object, integer given

余生颓废 提交于 2019-12-03 15:48:01
I have a many to one relationship between the entities Project and Course because each course can have many projects so many projects could be related to the same course. These are my entities: class Project{ /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; //... other fields ... //----------------------- DATABASE RELATIONSHIP ----------------// //PROJECT-COURSE - M:1 relationship /** * @ORM\ManyToOne(targetEntity="Course", inversedBy="project") * @ORM\JoinColumn(name="course_id", referencedColumnName="id") **/ private $course; and class