Hibernate version: 3.2.0.cr2, jdk 1.5
Code:
Code:
package test;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name="test")
class TestChild extends Test {
public TestChild () {}
}
package test;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
@Entity @MappedSuperclass
public class Test {
@Id
Integer id;
String txt;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTxt() {
return txt;
}
public void setTxt(String txt) {
this.txt = txt;
}
@SuppressWarnings("unchecked")
public static void main(String[] args) {
SessionFactory factory = new AnnotationConfiguration()
.addAnnotatedClass(Test.class)
.addAnnotatedClass(TestChild.class)
.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver")
.setProperty("hibernate.connection.url", "jdbc:postgresql://")
.setProperty("hibernate.connection.username", "")
.setProperty("hibernate.connection.password", "")
.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect")
.setProperty("hibernate.show_sql", "true")
.setProperty("hibernate.hbm2ddl.auto", "update")
.buildSessionFactory();
Session s = factory.openSession();
List<Test> l = s.createQuery("from Test").list();
for(Test t: l) {
System.out.println(t.getId());
}
Test t = (Test)s.createQuery("from Test e where txt=?")
.setString(0, "1").uniqueResult();
s.close();
}
Code:
insert into test values (1,1)
insert into test values (2,2)
Full stack trace of any exception that occurs:Code:
Exception in thread "main" org.hibernate.NonUniqueResultException: query did not return a unique result: 2
at org.hibernate.impl.AbstractQueryImpl.uniqueElement(AbstractQueryImpl.java:765)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:756)
at test.Test.main(Test.java:49)
The generated SQL (show_sql=true):Code:
Hibernate: select testchild0_.id as id1_, testchild0_.txt as txt1_ from test testchild0_ where testchild0_.txt=? for update of testchild0_
Hibernate: select test0_.id as id0_, test0_.txt as txt0_ from Test test0_ where test0_.txt=? for update of test0_
Why is output doubled:
Code:
1
2
1
2
and uniqueResult() fails?
Selecting from TestChild works fine...