I have two classes as below
#Entity
#Table(name = "Employee", schema = "...", catalog = "...")
public class EmployeeEntity implements Serializable, UserDetails {
#Id()
#Column(name = "EmployeeID", nullable = false, insertable = true, updatable = true, length = 20)
#Basic
#Column(name = "UserName", nullable = true, insertable = true, updatable = true, length = 20)
private String username;
#OneToMany
#JoinColumn(name="UserName")
private Set<EmployeesGroupsEntity> employeeGroups;
//Getter and setters
}
and
#Entity
#Table(name = "EmployeesGroups", schema = "...", catalog = "...")
public class EmployeesGroupsEntity implements Serializable {
#Id
#Column(name = "UserName", nullable = false, insertable = true, updatable = true, length = 20)
private String username;
#Basic
#Column(name = "Group", nullable = false, insertable = true, updatable = true, length = 255)
private String groups;
}
Now, to access the objects, I have the spring data rest repositories as below
#RepositoryRestResource(collectionResourceRel = "Employee", path = "Employee")
public interface IEmployeeRepository extends PagingAndSortingRepository<EmployeeEntity, String> {
EmployeeEntity getByUsername(String userName);
EmployeeEntity getByEmailAddress(String emailAddress);
}
and
#RepositoryRestResource(collectionResourceRel = "EmployeesGroups", path = "EmployeesGroups")
public interface IEmployeesGroupsRepository extends PagingAndSortingRepository<EmployeesGroupsEntity,String> {
}
with the above setup, I tried to access the URL
http://localhost:8080/Employee/12345
and I successfully got the result as below
{
"employeeId" : "12345",
"username" : "firstx",
"_links" : {
"self" : {
"href" : "http://localhost:8080/Employee/12345"
},
"employeeGroups" : {
"href" : "http://localhost:8080/Employee/12345/employeeGroups"
}
}
}
As a next step, when I access the URL
http://localhost:8080/Employee/12345/employeeGroups
i get the output as
{ }
Subsequently, I also tried with the header "text/uri-list". When i do this I get a response code of 204.
Please help me in resolving the issue.
Thanks
After giving up.. Found the answer after stumbling upon another question.
I just had to annotate the relationship with RestResource(exported=true)
#Entity
#Table(name = "Employee", schema = "...", catalog = "...")
public class EmployeeEntity implements Serializable, UserDetails {
#Id()
#Column(name = "EmployeeID", nullable = false, insertable = true, updatable = true, length = 20)
#Basic
#Column(name = "UserName", nullable = true, insertable = true, updatable = true, length = 20)
private String username;
#OneToMany
#RestResource(exported = true)
#JoinColumn(name="UserName")
private Set<EmployeesGroupsEntity> employeeGroups;
//Getter and setters
}
Related
Account Entity
#Getter
#Accessors(chain = true, fluent = true)
#NoArgsConstructor
#AllArgsConstructor(staticName = "of")
#ToString(of = {"customerName"}, callSuper = true)
#Entity
#Table(name = "ACCOUNTS",
uniqueConstraints = #UniqueConstraint(name = UNQ_CUSTOMER_NAME, columnNames = { "CUSTOMER_NAME" }),
indexes = {
#Index(name = IDX_CUSTOMER_ENTITY, columnList = "CUSTOMER_ENTITY")
}
)
public class Account extends BaseAutoAssignableVersionableEntity<String, Long> implements Diffable<Account> {
public static final String CUSTOMER_ENTITY = "Customer Entity";
public static final String CUSTOMER_REPORTING_MANAGER = "Customer Reporting Manager";
public static final String CUSTOMER_NAME = "Customer Name";
public static final String ACCOUNT_MANAGER = "Account Manager";
public static final String CITY = "City";
public static final String CUSTOMER_TIME_TRACKING = "Customer Time Tracking";
#NotNull
#Column(name = "CUSTOMER_NAME", nullable = false, length = 150)
#Audited(withModifiedFlag = true)
private String customerName; // Unique
#NotNull
#Size(min = 1, max = 4)
#Column(name = "CUSTOMER_GROUP", nullable = false, length = 4)
#Audited(withModifiedFlag = true)
private String customerGroup;
// #NotNull
#Column(name = "CUSTOMER_ENTITY", nullable = true, length = 150)
#Audited(withModifiedFlag = true)
private String customerEntity; // customer entity is optional and can be same for multiple accounts
#NotNull
#Column(name = "CUSTOMER_REPORTING_MANAGER", nullable = false, length = 150)
#Audited(withModifiedFlag = true)
private String customerReportingManager;
#Column(name = "CUSTOMER_TIME_TRACKING", length = 1)
#Audited(withModifiedFlag = true)
private boolean customerTimeTracking = false;
#NotNull
#OneToOne(fetch = FetchType.EAGER, optional = false)
#JoinColumn(name = "ACCOUNT_MANAGER_CODE", unique = false, nullable = false, foreignKey = #ForeignKey(name = FK_ACCOUNTS_MGR_RESOURCE_CODE))
#Audited(withModifiedFlag = true, targetAuditMode = RelationTargetAuditMode.NOT_AUDITED, modifiedColumnName = "ACCOUNT_MANAGER_CODE_MOD")
private Resource accountManager;
Resource Entity
#Getter
#Accessors(chain = true, fluent = true)
#NoArgsConstructor
#ToString(of = { "name" }, callSuper = true)
#Entity
// #formatter:off
#Table(name = "RESOURCES",
uniqueConstraints = {
#UniqueConstraint(name = UNQ_RESOURCES_LOGIN_ID, columnNames = {"LOGIN_ID"}),
#UniqueConstraint(name = UNQ_RESOURCES_EMAIL_ID, columnNames = {"EMAIL_ID"}),
#UniqueConstraint(name = UNQ_RESOURCES_PAYROLL_ID, columnNames = {"PAYROLL_ID"})
},
indexes = {
#Index(name = IDX_RESOURCES_NAME, columnList = "NAME")
}
)
// #formatter:on
public class Resource extends BaseAutoAssignableVersionableEntity<String, Long> implements Diffable<Resource> {
public static final String EMAIL_ID = "Email ID";
public static final String GRAYT_HR_ID = "Grayt HR ID";
public static final String NAME = "Name";
public static final String GENEDER = "Gender";
public static final String DESIGNATION = "Designation";
public static final String TYPE_OF_RESOURCE = "Resource Type";
public static final String STATUS_OF_RESOURCE = "Resource Status";
public static final String BASE_LOCATION = "Base Location";
public static final String DEPUTED_LOCATION = "Deputed Location";
public static final String PRIMARY_SKILLS = "Primary Skills";
public static final String SECONDARY_SKILLS = "Secondary Skills";
public static final String EXPECTED_JOINING_DATE = "Expected Joining Date";
public static final String ACTUAL_JOINING_DATE = "Actual Joining Date";
public static final String EXIST_DATE = "Exist Date";
// #Pattern(regexp = REGEX_LOGIN_ID, message = MESSAGE_LOGIN_ID_INVALID)
// #NotNull(message = MESSAGE_LOGIN_ID_MANDATORY)
#Column(name = "LOGIN_ID", nullable = false, length = 100)
private String loginId;
#Email(message = MESSAGE_EMAIL_INVALID)
#Column(name = "EMAIL_ID", nullable = true, length = 255)
#Audited(withModifiedFlag = true)
private String emailId;
#Pattern(regexp = REGEX_PAYROLL_ID, message = MESSAGE_PAYROLL_ID_INVALID)
#Column(name = "PAYROLL_ID", nullable = true, length = 100)
#Audited(withModifiedFlag = true, modifiedColumnName = "PAYROLL_ID_MOD")
private String payrollId;
#NotNull
#Column(name = "NAME", nullable = false, length = 255)
#Audited(withModifiedFlag = true)
private String name;
#NotNull
#Enumerated(EnumType.STRING)
#Column(name = "GENDER", nullable = false, length = 10)
#Audited(withModifiedFlag = true)
private Gender gender;
#NotNull
#OneToOne(fetch = FetchType.EAGER, optional = false)
#JoinColumn(name = "DESIGNATION_ID", unique = false, nullable = false, foreignKey = #ForeignKey(name = FK_RESOURCES_DESIGNATION_ID))
#Audited(withModifiedFlag = true, targetAuditMode = RelationTargetAuditMode.NOT_AUDITED, modifiedColumnName = "DESIGNATION_ID_MOD")
private Designation designation;
#NotNull
#OneToOne(fetch = FetchType.EAGER, optional = false)
#JoinColumn(name = "EMP_TYPE_CODE", unique = false, nullable = false, foreignKey = #ForeignKey(name = FK_RESOURCES_EMP_TYPE_CODE))
#Audited(withModifiedFlag = true, targetAuditMode = RelationTargetAuditMode.NOT_AUDITED, modifiedColumnName = "EMP_TYPE_CODE_MOD")
private EmploymentType employmentType;
public boolean isFTE() {
return (this.employmentType.equals(EmploymentType.fullTimeEmployee()));
}
#Audited(withModifiedFlag = true, modifiedColumnName = "EMP_STATUS_ID_MOD")
#OneToOne(optional = false, cascade = CascadeType.PERSIST, orphanRemoval = true)
#JoinColumn(name = "emp_status_id", unique = false, foreignKey = #ForeignKey(name = FK_RESOURCES_EMP_STATUS_ID))
private EmploymentStatus employmentStatus;
When i'm creating the account, used the existing resource as account manager and created successfully. Then fetch the history successfully. But unfortunately deleted the resource record in resource_aud table, then fetch the history. It's throwing below error
javax.persistence.EntityNotFoundException: Unable to find com.gspann.itrack.domain.model.staff.Resource with id IN10000
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$JpaEntityNotFoundDelegate.handleEntityNotFound(EntityManagerFactoryBuilderImpl.java:159)
at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:244)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:166)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:268)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:73)
at com.gspann.itrack.domain.model.staff.Resource_$$_jvst4e_12.name(Resource_$$_jvst4e_12.java)
at com.gspann.itrack.domain.model.business.Account.diff(Account.java:328)
at com.gspann.itrack.domain.model.business.Account.diff(Account.java:1)
at com.gspann.itrack.domain.model.common.audit.util.AuditQueryUtils.getAllRevisionById(AuditQueryUtils.java:66)
at com.gspann.itrack.domain.service.impl.AccountManagementServiceImpl.getAllRevisionByAccountCode(AccountManagementServiceImpl.java:268)
below is the query generated by hibernate envers
/* select
e__,
r
from
com.gspann.itrack.domain.model.business.Account_AUD e__,
com.gspann.itrack.audit.domain.CustomRevisionEntity r
where
e__.REVTYPE <> :_p0
and e__.originalId.code = :_p1
and e__.originalId.REV.id = r.id
order by
e__.originalId.REV.id asc */ select
account_au0_.code as code1_1_0_,
account_au0_.rev as rev2_1_0_,
customrevi1_.id as id1_49_1_,
account_au0_.revtype as revtype3_1_0_,
account_au0_.customer_entity as customer4_1_0_,
account_au0_.customer_entity_mod as customer5_1_0_,
account_au0_.customer_group as customer6_1_0_,
account_au0_.customer_group_mod as customer7_1_0_,
account_au0_.customer_name as customer8_1_0_,
account_au0_.customer_name_mod as customer9_1_0_,
account_au0_.customer_reporting_manager as custome10_1_0_,
account_au0_.customer_reporting_manager_mod as custome11_1_0_,
account_au0_.customer_time_tracking as custome12_1_0_,
account_au0_.customer_time_tracking_mod as custome13_1_0_,
account_au0_.account_manager_code as account14_1_0_,
account_au0_.account_manager_code_mod as account15_1_0_,
account_au0_.country_code as country16_1_0_,
account_au0_.country_code_mod as country17_1_0_,
customrevi1_.last_modified_on as last_mod2_49_1_,
customrevi1_.modified_by as modified3_49_1_,
customrevi1_.timestamp as timestam4_49_1_
from
accounts_aud account_au0_ cross
join
revinfo customrevi1_
where
account_au0_.revtype<>?
and account_au0_.code=?
and account_au0_.rev=customrevi1_.id
order by
account_au0_.rev asc
after calling getter method of resource it's generating another resource related query like below
/* select
e__
from
com.gspann.itrack.domain.model.staff.Resource_AUD e__
where
e__.originalId.REV.id = (
select
max(e2__.originalId.REV.id)
from
com.gspann.itrack.domain.model.staff.Resource_AUD e2__
where
e2__.originalId.REV.id <= :revision
and e__.originalId.code = e2__.originalId.code
)
and e__.REVTYPE <> :_p0
and e__.originalId.code = :_p1 */ select
resource_a0_.code as code1_48_,
resource_a0_.rev as rev2_48_,
resource_a0_.revtype as revtype3_48_,
resource_a0_.actual_joining_date as actual_j4_48_,
resource_a0_.actual_joining_date_mod as actual_j5_48_,
resource_a0_.email_id as email_id6_48_,
resource_a0_.email_id_mod as email_id7_48_,
resource_a0_.exit_date as exit_dat8_48_,
resource_a0_.exit_date_mod as exit_dat9_48_,
resource_a0_.gender as gender10_48_,
resource_a0_.gender_mod as gender_11_48_,
resource_a0_.name as name12_48_,
resource_a0_.name_mod as name_mo13_48_,
resource_a0_.payroll_id as payroll14_48_,
resource_a0_.payroll_id_mod as payroll15_48_,
resource_a0_.utilization as utiliza16_48_,
resource_a0_.utilization_mod as utiliza17_48_,
resource_a0_.utilization_type as utiliza18_48_,
resource_a0_.utilization_type_mod as utiliza19_48_,
resource_a0_.base_loc_id as base_lo20_48_,
resource_a0_.base_loc_id_mod as base_lo21_48_,
resource_a0_.deputed_loc_id as deputed22_48_,
resource_a0_.deputed_loc_id_mod as deputed23_48_,
resource_a0_.designation_id as designa24_48_,
resource_a0_.designation_id_mod as designa25_48_,
resource_a0_.emp_status_id as emp_sta26_48_,
resource_a0_.emp_status_id_mod as emp_sta27_48_,
resource_a0_.emp_type_code as emp_typ28_48_,
resource_a0_.emp_type_code_mod as emp_typ29_48_,
resource_a0_.image_id as image_i30_48_,
resource_a0_.image_id_mod as image_i31_48_
from
resources_aud resource_a0_
where
resource_a0_.rev=(
select
max(resource_a1_.rev)
from
resources_aud resource_a1_
where
resource_a1_.rev<=?
and resource_a0_.code=resource_a1_.code
)
and resource_a0_.revtype<>?
and resource_a0_.code=?
below is the code to fetch the revisions
AuditReader auditReader = this.getAuditReader();
return auditReader.createQuery().forRevisionsOfEntity(clazz, selectedEntitiesOnly, selectDeletedEntities);
My question is, why it's referring to audit table instead of main table?
Thank in advance
I am having an issue in setting up a many to many relationship in my entities. And I don't understand why
failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: cardgame.bean.User.card in cardgame.bean.Card.users
My Entities:
#MappedSuperclass
#Data
public class BaseEntity implements Serializable {
#Id
#Column(name = "id", nullable = false, unique = true)
private String id;
public BaseEntity() {
this.id = UUID.randomUUID().toString();
}
}
My user emtity:
#Data
#Entity
#Table(name = "users")
public class User extends BaseEntity {
#Column(name = "username", nullable = false, unique = true)
private String username;
#Column(name = "uuid", nullable = false)
private String uuid;
#Column(name = "email", nullable = false, unique = true)
private String email;
#OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private List<Card> cards;
#Column(name = "isActive", nullable = false)
private boolean isActive;
}
My card entity:
#Data
#Entity
#Table(name = "cards")
public class Card extends BaseEntity {
#OneToMany(mappedBy = "card")
private List<User> users;
#Column(name = "strength", nullable = false)
private int strength;
#Column(name = "isActive", nullable = false)
private boolean isActive;
}
The users and cards tables have a many-to-many relationship via user_card table:
#Data
#Entity
#Table(name = "user_card")
public class UserCard implements Serializable {
#Id
#ManyToOne
#JoinColumn(name = "user_id", nullable = false)
private User user;
#Id
#ManyToOne
#JoinColumn(name = "card_id", nullable = false)
private Card card;
#Column(name = "cardCount", nullable = false)
private int cardCount;
}
What am i doing incorrect. Please help me
I have a large DB on MySql Workbench and I'm trying to map the relationship between the entities on Eclipse Mars thanks to Hibernate and the JPA module. The fact is that I receive the error:
"In attribute 'personAddresses', the "mapped by" attribute 'peopleAdd' has an invalid mapping type for this relationship."
This are the entities involved.
1
I've to say that making a forward engineering, Hibernate creating for me an AddressId class, where the composite primary key of Address is mapped. I suspect that the problem could be this, but I'm not certain, can you help me please?
Under I post the code so that it's more clear to understand how the classes are implemented.
#Entity
#IdClass(AddressId.class)
#Table(schema = "YouDroop", name = "Address")
public class Address implements Serializable
{
...
private Collection<Person> peopleAdd = new HashSet<Person>();
#Id
#Column(name = "Address", length = 45, unique = true, nullable = false)
private String address;
#Id
#Column(name = "Number", unique = true, nullable = false)
private int number;
...
#ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
#JoinTable(
name = "PersonHasAddress",
joinColumns = {
#JoinColumn(name = "Address_Address", referencedColumnName = "Address", nullable = false),
#JoinColumn(name = "Address_Number", referencedColumnName = "Number", nullable = false)
},
inverseJoinColumns = {#JoinColumn(name = "Person_Email", referencedColumnName = "Email", nullable = false)}
)
public Collection<Person> getPeopleAddressed(){
return this.peopleAdd;
}
public void setPeopleAddressed(Collection<Person> people){
this.peopleAdd = people;
}
}
public class AddressId implements Serializable
{
private String address;
private int number;
public AddressId(){}
public AddressId(String address, int number) {
super();
this.address = address;
this.number = number;
}
...
}
#Entity
#Table(name = "Person", schema = "YouDroop", uniqueConstraints =
{ #UniqueConstraint(columnNames = "NickName"),
#UniqueConstraint(columnNames = "Password") })
public class Person implements Serializable
{
...
private Collection<Address> addresses = new HashSet<Address>();
...
#ManyToMany(fetch = FetchType.LAZY, mappedBy = "peopleAdd")
public Collection<Address> getPersonAddresses(){
return this.addresses;
}
public void setPersonAddresses(Collection<Address> addresses){
this.addresses = addresses;
}
}
Since you placed you #ManyToMany annotation on your getter method (or property) and not on the field. The mappedBy attribute should reference the property instead and not the field.
#ManyToMany
public Collection<Person> getPeopleAddressed() {
...
}
So your mappedBy attribute should have been
#ManyToMany(mappedBy="peopleAddressed")
public Collection<Address> getPersonAddresses() {
...
}
I'm Using JPA 2.1. I have 3 entities: Dr01 , Dr02 and Dr03 with the following structure:
public class Dr01 implements Serializable {
#OneToMany(cascade = CascadeType.ALL, mappedBy = "dr01")
private List<Dr02> dr02List;
}
public class Dr02 implements Serializable {
#OneToMany(cascade = CascadeType.ALL, mappedBy = "dr02")
private List<Dr03> dr03List;
#JoinColumn(name = "DR2CLM", referencedColumnName = "DR1CLM", insertable = false, updatable = false)
#ManyToOne(optional = false)
private Dr01 dr01;
}
public class Dr03 implements Serializable {
#JoinColumns({
#JoinColumn(name = "DR3CLM", referencedColumnName = "DR2CLM", insertable = false, updatable = false),
#JoinColumn(name = "DR3PTFN", referencedColumnName = "DR2PTFN", insertable = false, updatable = false)})
#ManyToOne(optional = false)
private Dr02 dr02;
private elementOBJ element;
}
public class elementOBJ implements Serializable {
#Column(name = "XXX")
private int id;
#Column(name = "YYY")
private int status;
}
I want to select from Dr01 and get only the Dr03 objects that have element objects which contains a value of 1 inside the status field.
How do I retrieve dr03List filtered by it's status value? (filtered not after the select).
Thank's In Advance.
Options that may be of assistance:
Create a DB view based on status of DR03 table and map your
entity to that.
Use JPA Inheritance using status as a
DiscriminatorColumn.
If using Hibernate use the non-JPA #Where
annotation to filter the collection
I am currently trying to display information requested via JPA 2.0 (eclipselink). I am using glassfish 3.0.1 and netbeans 6.9.1 as IDE. My persistence entities are created under netbeans option "create entity classes from database". My shcema is designed with workbench mysql, and my server is of course mysql. I really cant figure out what creates this #JoinColumns error.
javax.servlet.ServletException: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [myprojectPU] failed.
Internal Exception: Exception [EclipseLink-7220] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The #JoinColumns on the annotated element [field userInfo] from the entity class [class com.myproject.jpa.UserId] is incomplete. When the source entity class uses a composite primary key, a #JoinColumn must be specified for each join column using the #JoinColumns. Both the name and the referencedColumnName elements must be specified in each such #JoinColumn.
This part randomly swaps from [field userInfo] from the entity class [class com.myproject.jpa.UserId] to [field userIdList] from the entity class [class com.myproject.jpa.Cell]. So both classes probably have the same issue.
Here are my classes:
#Entity
#XmlRootElement
#Table(name = "user_id", catalog = "workitout", schema = "")
public class UserId implements Serializable {
private static final long serialVersionUID = 1L;
#EmbeddedId
protected UserIdPK userIdPK;
#Basic(optional = false)
#Column(name = "email", nullable = false, length = 45)
private String email;
#Basic(optional = false)
#Column(name = "password", nullable = false, length = 45)
private String password;
#ManyToMany(mappedBy = "userIdList")
private List<Cell> cellList;
#JoinColumn(name = "USER_INFO_id_info", referencedColumnName = "id_info", nullable = false, insertable = false, updatable = false)
#ManyToOne(optional = false)
private UserInfo userInfo;
...
}
#Entity
#XmlRootElement
#Table(name = "user_info", catalog = "workitout", schema = "")
public class UserInfo implements Serializable {
private static final long serialVersionUID = 1L;
#EmbeddedId
protected UserInfoPK userInfoPK;
#Basic(optional = false)
#Column(name = "fullName", nullable = false, length = 45)
private String fullName;
#Basic(optional = false)
#Column(name = "city", nullable = false, length = 45)
private String city;
#Basic(optional = false)
#Column(name = "gender", nullable = false, length = 10)
private String gender;
#Basic(optional = false)
#Column(name = "isCoach", nullable = false)
private boolean isCoach;
#Column(name = "age")
private Integer age;
#Column(name = "description", length = 200)
private String description;
#Column(name = "linkImage", length = 45)
private String linkImage;
#Column(name = "friendList", length = 500)
private String friendList;
#Column(name = "coachList", length = 500)
private String coachList;
#JoinColumn(name = "USER_SPORT_id_sport", referencedColumnName = "id_sport", nullable = false, insertable = false, updatable = false)
#ManyToOne(optional = false)
private UserSport userSport;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "userInfo")
private List<UserId> userIdList;
...
}
*The first error was solved, but the [field userIdList] from the entity class [class com.myproject.jpa.Cell]. remains. Ive added the code of my cell table:
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
#Entity
#XmlRootElement
#Table(name = "cell", catalog = "workitout", schema = "")
#NamedQueries({
#NamedQuery(name = "Cell.findAll", query = "SELECT c FROM Cell c"),
#NamedQuery(name = "Cell.findByIdCell", query = "SELECT c FROM Cell c WHERE c.idCell = :idCell"),
#NamedQuery(name = "Cell.findByName", query = "SELECT c FROM Cell c WHERE c.name = :name")})
public class Cell implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Basic(optional = false)
#Column(name = "id_cell", nullable = false)
private Integer idCell;
#Basic(optional = false)
#Column(name = "name", nullable = false, length = 45)
private String name;
#ManyToMany
#JoinTable(name = "user_id_has_cell", joinColumns = {
#JoinColumn(name = "cell_id_cell", referencedColumnName = "id_cell", nullable = false)}, inverseJoinColumns = {
#JoinColumn(name = "USER_ID_id", referencedColumnName = "id", nullable = false),
#JoinColumn(name = "USER_INFO_id_info", referencedColumnName = "id_info", nullable = false, insertable = false, updatable = false),
#JoinColumn(name = "USER_SPORT_id_sport", referencedColumnName = "id_sport", nullable = false, insertable = false, updatable = false)
})
private List<UserId> userIdList;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "cell")
private List<WorkoutSession> workoutSessionList;
public Cell() {
}
public Cell(Integer idCell) {
this.idCell = idCell;
}
public Cell(Integer idCell, String name) {
this.idCell = idCell;
this.name = name;
}
public Integer getIdCell() {
return idCell;
}
public void setIdCell(Integer idCell) {
this.idCell = idCell;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<UserId> getUserIdList() {
return userIdList;
}
public void setUserIdList(List<UserId> userIdList) {
this.userIdList = userIdList;
}
public List<WorkoutSession> getWorkoutSessionList() {
return workoutSessionList;
}
public void setWorkoutSessionList(List<WorkoutSession> workoutSessionList) {
this.workoutSessionList = workoutSessionList;
}
#Override
public int hashCode() {
int hash = 0;
hash += (idCell != null ? idCell.hashCode() : 0);
return hash;
}
#Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Cell)) {
return false;
}
Cell other = (Cell) object;
if ((this.idCell == null && other.idCell != null) || (this.idCell != null && !this.idCell.equals(other.idCell))) {
return false;
}
return true;
}
Error message describes the problem pretty clearly - UserInfo has a composite key, therefore you need to specify several #JoinColumns, one column for each field of the composite key:
#JoinColumns({
#JoinColumn(...),
#JoinColumn(...)
})
#ManyToOne(optional = false)
private UserInfo userInfo;
From the error message I would try to add the following to your class UserId:
#JoinColumn(name = "USER_INFO_uSERSPORTidsport", referencedColumnName = "uSERSPORTidsport", nullable = false, insertable = false, updatable = false)
#ManyToOne(optional = false)
private UserSport usersport;