I'm using Spring 3.2.3, JPA 2.1, JUnit 4.11. I'm trying to run a junit test and I keep getting the abstract schema type is unknown error. Here is my entity (truncated for space, it has all the getters and setters):
#Entity
#Table(name = "WEB_PROFILES")
public class TestWebProfile implements Serializable {
private static final long serialVersionUID = 1L;
#Transient
private String forward;
#Column(name = "ACCESS_FLAG")
private String accessFlag;
#Temporal(TemporalType.DATE)
#Column(name = "ACCESS_FLAG_UPD_DATE")
private Date accessFlagUpdDate;
#Column(name = "ACCESS_RESET_INTERVAL")
private BigDecimal accessResetInterval;
#Column(name = "ACCOUNT_TYPE")
private String accountType;
#Column(name = "CREATED_BY")
private String createdBy;
#Column(name = "E_MAIL")
private String eMail;
#Column(name = "FAILED_LOGIN_ATTEMPTS")
private BigDecimal failedLoginAttempts;
#Column(name = "FIRST_NAME")
private String firstName;
#Temporal(TemporalType.DATE)
#Column(name = "FROI_ACCESS_APPROVE_DENY_DATE")
private Date froiAccessApproveDenyDate;
#Column(name = "FROI_ACCESS_APPROVED_FLAG")
private String froiAccessApprovedFlag;
#Column(name = "FROI_ACCESS_REQUESTED")
private String froiAccessRequested;
#Column(name = "FROI_APPROVED_BY")
private String froiApprovedBy;
#Temporal(TemporalType.DATE)
#Column(name = "FROI_CONFIRM_EMAIL_SENT_DATE")
private Date froiConfirmEmailSentDate;
#Temporal(TemporalType.DATE)
#Column(name = "FROI_LETTER_SENT_DATE")
private Date froiLetterSentDate;
#Column(name = "LAST_LOGON_ADDR")
private String lastLogonAddr;
#Temporal(TemporalType.DATE)
#Column(name = "LAST_LOGON_DATE")
private Date lastLogonDate;
#Column(name = "LAST_NAME")
private String lastName;
#Column(name = "LAST_UPDATED_BY")
private String lastUpdatedBy;
#Column(name = "LAST_UPDATED_BY_NAME")
private String lastUpdatedByName;
#Column(name = "LAST_UPDATED_BY_SU_ID")
private BigDecimal lastUpdatedBySuId;
#Temporal(TemporalType.DATE)
#Column(name = "MAIL_SENT_DATE")
private Date mailSentDate;
#Temporal(TemporalType.DATE)
#Column(name = "MAINT_DATE")
private Date maintDate;
#Temporal(TemporalType.DATE)
#Column(name = "NEW_PIN_REQ_DATE")
private Date newPinReqDate;
#Column(name = "PASSWORD")
private String password;
#Transient
private String newPassword;
#Temporal(TemporalType.DATE)
#Column(name = "PASSWORD_UPD_DATE")
private Date passwordUpdDate;
#Column(name = "PHONE")
private String phone;
#Column(name = "PIN")
private String pin;
#Column(name = "POLICY_NUM")
private BigDecimal policyNo;
#Column(name = "PROFILE_CLASS_CODE")
private String profileClassCode;
#Temporal(TemporalType.DATE)
#Column(name = "PROFILE_REQ_DATE")
private Date profileReqDate;
#Temporal(TemporalType.DATE)
#Column(name = "PROFILE_UPDATE_DATE")
private Date profileUpdateDate;
#Column(name = "REMOTE_ADDR")
private String remoteAddr;
#Column(name = "SESSIONID")
private String sessionid;
#Column(name = "SUBSCRIBER_FLAG")
private String subscriberFlag;
#Column(name = "USER_ID")
private BigDecimal userId;
#Id
#Column(name = "USER_NO")
private BigDecimal userNo;
#Column(name = "USERNAME")
private String username;
My JUnit test:
#Test
public void testGetWebProfileByUsername() {
TestWebProfile wp = sso.getWebProfile("MARLENE");
System.out.println("name :" + wp.getFirstName());
System.out.println("last name :" + wp.getLastName());
}
My DAO implementation:
#Override
public TestWebProfile getWebProfile(String username) {
String sqlString = "select w from TestWebProfile w where w.username =:username";
return (TestWebProfile) getEntityManager()
.createQuery(sqlString, TestWebProfile.class)
.setParameter("username", username).getSingleResult();
}
After Googling for the past hour, the only culprit I found that seem to make sense was not having the #Id and #Column annotations, but I have those on the userNo variable. Any help that can be provided would be greatly appreciated!
Have a look at this. It gives some suggesstion for the same case http://java.dzone.com/tips/the-nasty-jpa-unknown-abstract
If you are using Java SE you have to add the fully qualified name of your entity class in persistence.xml, like so
<persistence-unit ...>
<class>your.custom.package.TestWebProfile</class>
</persistence-unit>
Omitting the package part may lead to your error.
Try adding inside your persistence-unit tag as follows:
<exclude-unlisted-classes>false</exclude-unlisted-classes>
For some reason in my case although I was listing all the classes inside my persistence unit using fully qualified names, eclipseLink didn't recognize them. Once added that line, it just works.
I was using:
Java SE 8
Maven Project
EclipseLink (Local not an application server)
Netbeans
Related
I am using Spring data jpa for creating service. In following code I am using Querydsl for implementing search filter on grid. But for building name I am not able to filter the grid. I am getting
java.lang.NullPointerException: null.
For grid data is coming from multiple tables. I am not using joining for that. I mapped models classes with each other
#Service
public class RoomTransferService {
#Autowired
RoomTransferRepository roomTransferRepo;
#PersistenceContext
EntityManager em;
public List<RoomTransfer> findRoomTransfer(String sStatus, String sBuildName, String deptFrom, String deptTo) {
QRoomTransfer roomTransfer = QRoomTransfer.roomTransfer;
JPAQuery<RoomTransfer> query = new JPAQuery<RoomTransfer>(em);
query.from(roomTransfer);
// filter the details
if (sStatus != null) {
query.where(roomTransfer.sStatus.eq(sStatus));
}
// not filtering
if(sBuildName !=null) {
query.where(roomTransfer.roomDeptMap.room.building.sBuildName.eq(sBuildName));
}
List<RoomTransfer> QueryResultRoomTramsfer=query.fetch();
Return QueryResultRoomTramsfer;
Room class
#Entity
#Table(name = "room")
#JsonInclude(JsonInclude.Include.NON_NULL)
public class Room implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "room_seq_generator")
#SequenceGenerator(name = "room_seq_generator", sequenceName = "room_seq")
#Column(name = "nroom_id")
public Integer nRoomId;
#Column(name = "ncampus_id")
public Integer nCampusId;
#Column(name = "nbuild_id")
public Integer nBuildId;
#Column(name = "ninst_id")
public Integer nInstId;
#Column(name = "sfloor")
public String sFloor;
#Column(name = "sroom_number")
public String sRoomNumber;
#Column(name = "sroom_desc")
public String sRoomDesc;
#Column(name = "scomments")
public String sComments;
#Column(name = "daccepted_date")
public Timestamp dAcceptedDate;
#Column(name = "ssurveyor")
public String sSurveyor;
#Column(name = "narea")
public Integer nArea;
#Column(name = "ncrt_code_id")
public Integer nCRTCodeId;
#Column(name = "ncmn_room_bln")
public Integer nCMNRoomBln;
#Column(name = "nunvalidated_bln")
public Integer nUnvalidatedBln;
#Column(name = "sbfr_field")
public String sBfrField;
#Column(name = "ntemp_room_id")
public Integer nTempRoomId;
#Column(name = "bis_active")
public Boolean bIsActive;
#Column(name = "bis_jointuse")
public Boolean bIsJointuse;
#Column(name = "sstations_desc")
public String sStationsDesc;
#Column(name = "ddeleted_on")
public Timestamp dDeletedOn;
#Column(name = "ndeleted_by")
public Integer nDeletedBy;
#Column(name = "bis_incluster")
public Boolean bIsIncluster;
#Column(name = "bis_service_center_activity")
public Boolean bisServiceCenterActivity;
#Column(name = "service_center_comments")
public String serviceCenterComments;
#ManyToOne(optional = true)
#JoinColumn(name = "nbuild_id", insertable = false, updatable = false)
public Building building;
The NPE that you get is probably related to the limitation of QueryDsl where you cannot exceed four levels.
Your code exceeds four levels.
roomTransfer.roomDeptMap.room.building.sBuildName
You can read more on official documentation or related stackoverflow's question.
In the first link there is a solution to overcome this issue using QueryInit annotation.
If you do not want to alter your entity class you can perform a join (if possible) with an alias for the first 2 or 3 levels and then use this alias to complete the query.
What I'm trying to do is to load only promotions with promotion.enabled=1 AND PromotionType.enabled=1.
I tried to add the #Where annotation in both tables but when I set promotionType, enabled to 0 I´m getting an error.
On the other hand, I also tried to add the #WhereJoinTable clause to promotionType but I'm not getting the expected result. Any help?
The first one:
#Entity
#Table(name = "HOTEL_PROMOTION")
#Where(clause = "enabled=1")
public class Promotion implements Serializable {
private static final long serialVersionUID = 257070400893576505L;
#Id
#Column(name = "PROMOTION_ID")
private Long id;
#Column(name = "CODE")
private String code;
#Column(name = "NAME")
private String name;
#Column(name = "PRIORITY")
private Long priority;
#ManyToOne
#JoinColumn(name = "PROMOTION_TYPE_ID")
#WhereJoinTable(clause = "enabled=1")
private PromotionType promotionType;
#Column(name = "ENABLED")
private Boolean enabled;
}
The second one:
#Entity
#Table(name = "HOTEL_PROMOTION_TYPE")
public class PromotionType implements Serializable {
private static final long serialVersionUID = -8359165117733458987L;
#Id
#Column(name = "PROMOTION_TYPE_ID")
private Long id;
#Column(name = "CODE")
private String code;
#Column(name = "NAME")
private String name;
#Column(name = "STYLE")
private String style;
#Column(name = "ENABLED")
private Boolean enabled;
}
I am not able to check the equality of two dates in JPA. The comparison below works fine until I add the date of Birth. I am not sure if my JPQL is correct:
TypedQuery<Applicant> query = em.createQuery("select app "
+ "from Applicant app where "
+ "app.firstName = :firstName AND app.middleName = :middleName "
+ "AND app.lastName = :lastName"
+" AND app.dob = :dateOfBirth", Applicant.class);
query.setParameter("firstName", searchableApplicant.getFirstName().trim());
query.setParameter("middleName", searchableApplicant.getMiddleName().trim());
query.setParameter("lastName", searchableApplicant.getLastName().trim());
query.setParameter("dateOfBirth", searchableApplicant.getDob());
Applicant Object properties:
public class Applicant implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Basic(optional = false)
#Column(name = "applicant_id")
private Integer applicantId;
#Size(max = 45)
#Column(name = "first_name")
private String firstName;
#Size(max = 45)
#Column(name = "middle_name")
private String middleName;
#Size(max = 45)
#Column(name = "last_name")
private String lastName;
#Size(max = 45)
#Column(name = "maiden_name")
private String maidenName;
#Column(name = "dob")
#Temporal(TemporalType.DATE)
private Date dob;
The JSF date converters defaults to UTC timezone. When intepreting those dates using UTC timezone (as JSF by default does), you will get hours back in time and thus the previous day will be represented.
The solution is right here:
JSF page reflects Date incorrectly - 1 Day shifted
I am pretty new to java and data entities and I am getting the, "Exception Description: An incompatible mapping has been encountered between [class com.store.Product] and [class com.store.Cart]." error and not sure why (obviously).
My mappings are as follows:
Product.java
#Basic(optional = false)
#NotNull
#Column(name = "P_QTY")
private Integer pQty;
#Column(name = "P_PRICE")
private BigDecimal pPrice;
private static final long serialVersionUID = 1L;
#Id
#Basic(optional = false)
#NotNull
#Column(name = "P_ID")
private String pId;
#Size(max = 10)
#Column(name = "P_NAME")
private String pName;
#Size(max = 20)
#Column(name = "P_DESC")
private String pDesc;
#OneToMany(mappedBy = "pId")
Cart.java
#Id
#Basic(optional = false)
#NotNull
#Column(name = "C_ID")
private String cId;
#Basic(optional = false)
#NotNull
#Column(name = "C_QTY")
private Integer cQty;
#Column(name = "C_PRICE")
private Double cPrice;
private static final long serialVersionUID = 1L;
#Id
#Basic(optional = false)
#NotNull
#Size(min = 1, max = 10)
#JoinColumn(name = "P_ID", referencedColumnName = "P_ID")
#ManyToOne
private String pId;
Any ideas? Like I said, I'm new to data entities and have done enough reading to confuse myself at this point so I apologize for any and all idiocy on my part.
Thanks in advance.
I have a two entities with relation between they are.
public class Client implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue
private Integer id;
#NotNull
#Size(min = 3, max = 25)
private String firstName;
#NotNull
#Size(min = 3, max = 25)
private String lastName;
private String login;
private String password;
#OneToMany(mappedBy = "client")
private List<Project> projects;
}
and
public class Project implements Serializable {
private static final long serialVersionUID = 4762714047114442539L;
#Id
#GeneratedValue
private Integer id;
private String name;
#Temporal(TemporalType.TIMESTAMP)
private Date startDate;
#ManyToOne
#JoinColumn
private Client client;
}
I want to made a query using jpametamodel and Criteria API. Like this:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Project> q = cb.createQuery(Project.class);
Root<Project> projects = q.from(Project.class);
q.where(cb.equal(projects.get(Project_.client), clientId));
Problem for me that i don't know how to get access to "id" property of Client in this string:
q.where(cb.equal(projects.get(Project_.client), clientId));
i want to get something like
q.where(cb.equal(projects.get("client.id"), clientId));
but with jpametamodel. It is possible? :)
Tried something like this?
projects.get(Project_.client).get(Client_.id);