Greetings, I am having an issue working with Hibernate and enforcing unique data members when inserting.
Here are my abridged Entity objects:
Workflow:
Code:
@Entity
public class Workflow {
private long wfId;
private Set<Service> services;
/** Getter/Setter for wfId */
...
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "workflow_services",
joinColumns = @JoinColumn(name = "workflow_id"),
inverseJoinColumns = @JoinColumn(name = "service_id"))
public Set<Service> getServices() {
return services;
}
Service:
Code:
@Entity
public class Service {
private long serviceId;
private String serviceName;
/** Getter/Setter for serviceId */
...
@Column(unique=true,nullable=false)
public String getServiceName() {
return serviceName;
}
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "service_operations",
joinColumns = { @JoinColumn(name = "serviceId") },
inverseJoinColumns = { @JoinColumn(name = "operationId") })
public Set<Operation> getOperations() {
return operations;
}
Operation:
Code:
@Entity
public class Operation {
private long operationId;
private String operationName;
/** Getter/Setter for operationId */
@Column(unique=true,nullable=false)
public String getOperationName() {
return operationName;
}
----------------------------
My issue:
Although I have stated in each object what is SUPPOSED to be unique, it is not being enforced.
Inside my Workflow object, I maintain a Set of Services. Each Service maintains a list of Operations. When a Workflow is saved to the database, I need it to check if the Services and Operations it currently uses are already in the database, if so, associate itself with those rows.
Currently I am getting repeats within my Services and Operations tables.
I have tried using the annotation:
Code:
@Table( uniqueConstraints)
but have had zero luck with it.
Any help would be greatly appreciated