This blog shares some errors we met, and some problem we encountered, to assist future reader.
org.hibernate.LazyInitializationException
Detailed error message is following:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: entity.Branch.plans, could not initialize proxy - no SessionHere is a strange solution for lazy fetch and finally I give bidirectional relationship and this problem solved.
@OneToOne with Shared Primary Key
Code sample:
public class User {
    @Id Integer id;
    @OneToOne(mappedBy = "user")
    @PrimaryKeyJoinColumn
    Account account;
}
public class Account {
    @Id Integer id;
    @MapsId
    @OneToOne
    @JoinColumn(name = "uid")
    User user;  
    public Account(User user) {
        this.user = user;
        /*
        id = user.getUid();
        can't assign it, why?
        error: null value was assigned to a property of primitive type setter uid
         */ 
    }
}JPA-style positional param was not an integral ordinal
My original query:
query="select pd from PlanDetail pd where pd.plan.branch.bid = ?1"+
"and pd.plan.pdate = ?2 and pd.dessert.did = ?3"This can easily happen when you split your query in multiple line like above example. Notice this is no space between ?1 and and. Adding a space fix this problem.
Mis-spelled Action Name Cause Exception Setting Some Variable In Action Class
Example:
Unexpected Exception caught setting 'pw' on 'class 
com.opensymphony.xwork2.ActionSupport: Error setting expression 'pw' 
with value ['123123', ]Of course, no setter for your field also cause this error.
According to TLD or attribute directive in tag file, attribute value does not accept any expressions
Wrong usage
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>Explanation 
Right usage
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>Written with StackEdit.
评论
发表评论