관련 검색 예

	

OneToManyUser TAddress             ,             ,         TAddress          OneToManyUser address       ,      SQL  select this_.id as id5_0_, this_.name as name5_0_, this_.age as age5_0_ from otmuser this_ where (1=1)
           otmuser     ,    :
OneToManyUser user2 = new OneToManyUser();
TAddress address = new TAddress();
address.setAddress("ShangHai3");
user2.addAddresses(address);
List list5 =
session.createCriteria(OneToManyUser.class).add(Example.create(user2)).list();
for(int i = 0; i < list5.size(); ++i){
System.out.println(((OneToManyUser)list5.get(i)).getId());
}

  addAddresses()   
public void addAddresses(TAddress address){
address.setUser(this);
this.getAddresses().add(address);
}
    

  :JavaEye        ,     。            。       ,                   。
    :      

    :      

        ?Example                    ?

         (   join)
              
PS:             
           

    !        
PS:                       ?
            ,       ,              

                 
          

     Example API,        
List results = session.createCriteria(Parent.class)
.add( Example.create(parent).ignoreCase() )
.createCriteria("child")
.add( Example.create( parent.getChild() ) )
.list();
  API  ,       ,  
Exception in thread "main" java.lang.ClassCastException: java.util.HashSet
at org.hibernate.criterion.Example.getEntityMode(Example.java:247)
at org.hibernate.criterion.Example.toSqlString(Example.java:177)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:333)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:82)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1514)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at org.hibernate.impl.CriteriaImpl$Subcriteria.list(CriteriaImpl.java:458)
at com.hibernate.lockandquery.ComplexQuery.main(ComplexQuery.java:35)
    

좋은 웹페이지 즐겨찾기