Composite key joins in hibernate
by Sameer Sarmah
I am using hibernate to persist two tables,`Project` and `Department`.
`Department` table has a composite primary key `DeptCompID`.
@Embeddable
public class DeptCompID implements Serializable
{
@Column(name = "DeptID")
private int DeptID;
@Column(name = "RoleID")
private int RoleID;
//getters and setters
}
@Entity
public class Department implements Serializable
{
@EmbeddedId
private DeptCompID id;
private String name;
@OneToOne(mappedBy="department",targetEntity = Project.class)
private Project pro;
//getters and setters
}
@Entity
public class Project
{
@Id
private int ProId;
@OneToOne(targetEntity = Department.class)
@MapsId("DeptID")
@JoinColumns({
@JoinColumn(name = "RoleID", referencedColumnName = "RoleID"),
@JoinColumn(name = "DeptID", referencedColumnName = "DeptID")
})
private Department department;
//getters and setters
}
**Code to persist the tables**
Department department = new Department();
department.setName("HR");
DeptCompID cpk=new DeptCompID();
cpk.setRoleID(10);
cpk.setDeptID(60);
department.setId(cpk);
Project pro=new Project();
pro.setDepartment(department);
pro.setProId(10);
department.setPro(pro);
session.save(department);
session.save(pro);
Everytime I persist the tables Project and Department the `DeptID` column in `Project` table is always null when it should be 60.
why is `@MapsId("DeptID")` not working?Could some provide a resolution.
Posted by forums
Original post: https://community.jboss.org/message/878168#878168
10 years, 5 months
Infinispan example code for entry based locking
by Karminder Singh
Hi,
I am new to infinispan. I am trying to use infinispan database with multiple writers and readers. I need help on the following:
1. Sample code that shows how to acquire locks on records in distributed mode. Also, how can this be done in replicated mode.
2. If I make the infinispan cache persistent, will it be OK to use locking then also. What are the things I should keep in mind.
3. Is there a way I can lock the whole infinispan cluster distributed across different nodes. The idea behind this is, I would like to acquire a set of records before performing operation and I want to ensure that only one process acquires all these locks.
I could not find example codes, and descriptions for all the APIs. Please help if they are available.
Thanks,
Karm
Posted by forums
Original post: https://community.jboss.org/message/880856#880856
10 years, 5 months