I am getting the following exception and have done all this 1000 times before but now I am getting errors:
ValidationException Exception Description: [class com.smartphonedev.rsvplaw.entities.Staff] uses a non-entity [class com.smartphonedev.rsvplaw.entities.Address] as target entity in the relationship attribute [field addresses]..
here are the entities in question. Can someone help me identify what is wrong with my relationships?
<code>
@Entity
@Table(name="address")
public class Address implements Serializable,
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name="addressType")
@Enumerated(EnumType.ORDINAL)
private AddressType addressType;
@Column(name="streetLineOne")
private String streetLineOne;
@Column(name="streetLineTwo")
private String streetLineTwo;
@Column(name="city")
private String city;
@Column(name="adState")
private String state;
@Column(name="postCode")
private String postCode;
@OneToMany(fetch=FetchType.LAZY, targetEntity=PhoneNumber.class, cascade = {CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH},orphanRemoval=true)
@JoinColumn(name="phoneNumbers")
private Collection<PhoneNumber> phoneNumbers;
…..
}
@Entity
@Table(name="staff")
public class Staff implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
//private Profile profile;
@OneToOne(fetch=FetchType.LAZY,cascade = {CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH})
@JoinColumn(name="permission")
private Permission permission;
@OneToOne(fetch=FetchType.LAZY,cascade = {CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH})
@JoinColumn(name="login")
private Login login;
@Column(name="firstName")
private String firstName;
@Column(name="surnameName")
private String surnameName;
@Column(name="emailAddress")
private String emailAddress;
@OneToMany(fetch=FetchType.LAZY, targetEntity=PhoneNumber.class, cascade = {CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH},orphanRemoval=true)
@JoinColumn(name="phoneNumbers")
private Collection<PhoneNumber> phoneNumbers;
@OneToMany(fetch=FetchType.LAZY, targetEntity=Address.class, cascade = {CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH},orphanRemoval=true)
@JoinColumn(name="addresses")
private Collection<Address> addresses;
}
</code
Adding the phoneNumber class
@Entity
@Table(name="phone")
public class PhoneNumber implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name="numberType")
@Enumerated(EnumType.ORDINAL)
private PhoneNumberType numberType;
@Column(name="phoneNumber")
private String phoneNumber;
}
</code>
Adding persistance.xml
<code> <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="RSVPLawServerPU" transaction-type="JTA"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <jta-data-source>jdbc/RSVPLaw</jta-data-source> <class>com.smartphonedev.rsvplaw.entities.PhoneNumber</class> <class>com.smartphonedev.rsvplaw.entities.Address</class> <exclude-unlisted-classes>false</exclude-unlisted-classes> <shared-cache-mode>NONE</shared-cache-mode> <validation-mode>CALLBACK</validation-mode> <properties> <property name="eclipselink.target-server" value="SunAS9"/> <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/> <property name="eclipselink.ddl-generation" value="create-tables"/> <property name="eclipselink.ddl-generation.output-mode" value="database"/> <property name="javax.persistence.schema-generation.database.action" value="create"/> </properties> </persistence-unit> </persistence> <code>
@OneToMany
should bemappedBy
, while@ManyToOne
should be followed by@JoinColumn
– guidoAddress
listed in thepersistence.xml
? Looks like it's not "known" to be an entity. – geert3