当我尝试为@OneToMany关系选择数据时,我收到此错误, 这是我的实体:
@Entity
@Table(name = "PERSON")
@DynamicInsert
public class Person
implements java.io.Serializable
{
//properties ....
private Set<Adress> adresses = new HashSet<Adress>( 0 );
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "person")
public Set<Adress> getAdresses()
{
return this.adresses;
}
public void setAdresses( Set<Adress> adresses )
{
this.adresses = adresses;
}
}
//Adress class
@Entity
@Table(name = "ADRESS")
public class Adress
implements java.io.Serializable
{
//properties ....
private Person person;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "NO_PERSON")
public Constat getPerson()
{
return this.person;
}
public void setPerson( Person person )
{
this.person = person;
}
}
当我尝试获取一个Adress对象时,我收到错误,这是我的服务:
public Adress findLastAdressByType( String noPerson, String type )
{
List<Adress> result = getHibernateTemplate().find( "from Adress as Adress where Adress.person.noPerson = ? and Adress.type = ? order by dateCreation desc ", noPerson, type );
if ( !result.isEmpty() )
{
return result.get( 0 );
}
else
{
return null;
}
}
这是我的getHibernateTemplate()。find()服务:
@SuppressWarnings("unchecked")
public <T> List<T> find( String queryString, Object... values )
throws DataAccessException
{
Query query = getSessionFactory().getCurrentSession().createQuery( queryString );
for ( int i = 0; i < values.length; i++ )
{
query.setParameter( i, values[i] );
}
return query.list();
}
我收到错误&#34;批量更新从update [0]返回意外的行数;实际行数:0;预期:1&#34;在ligne:
return query.list();
和
List<Adress> result = getHibernateTemplate().find( "from Adress as Adress where Adress.person.noPerson = ? and Adress.type = ? order by dateCreation desc ", noPerson, type );
:
任何人都可以帮我知道究竟是什么问题,这是hibernate的一个问题,还是我的关系注释有问题。
问候!