Hello,
I'm newcomer of this forum. And I think You can give me advise about problem below.
Thanks in advance!
Best regards,
Alex
Hibernate version: 3.2
Mapping documents:
I have annotated Java class:
@Entity
@Table(name = "TEST", uniqueConstraints = {})
public class Test {
////////////////////////////////////////////////
// Fields
////////////////////////////////////////////////
private Integer id;
private Integer klasse;
private Integer parentId;
///////////////////////////////////////////////////////
// Constructors
///////////////////////////////////////////////////////
/**
* Creates new instance of Test class
*/
public Test() {
}
/**
* Creates new instance of Test class
*
* @param id specific test identifier
*/
public Test(Integer id) {
this.id = id;
}
///////////////////////////////////////////////////////
// Property accessors
///////////////////////////////////////////////////////
@Id
@Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true, precision = 22, scale = 0)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "KLASSE", unique = false, nullable = true, insertable = true, updatable = true, precision = 22, scale = 0)
public Integer getKlasse() {
return this.klasse;
}
public void setKlasse(Integer klasse) {
this.klasse = klasse;
}
@Column(name = "PARENT_ID", unique = false, nullable = true, insertable = true, updatable = true, precision = 22, scale = 0)
public Integer getParentId() {
return this.parentId;
}
public void setParentId(Integer parentId) {
this.parentId = parentId;
}
}
Code between sessionFactory.openSession() and session.close():
I've created method:
List list = session.createSQLQuery("select t.ID as {currentTest.id} from Test t where connect_by_isleaf=1 start with t.ID=2 connect by prior t.ID=t.PARENT_ID order by t.KLASSE").
addEntity("currentTest", Test.class).list()
It issues exception below.
If I replace
select t.ID as {currentTest.id}
with
*
all is working without problems.
So I just need to get not all data to given entity but only some attributes.
Full stack trace of any exception that occurs:
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not execute query; bad SQL grammar [select t.ID as ID0_0_ from Test t where connect_by_isleaf=1 start with t.ID=2 connect by prior t.ID=t.PARENT_ID order by t.KLASSE]; nested exception is java.sql.SQLException: Не.о.уст.мое .м. сто...а
java.sql.SQLException: Не.о.уст.мое .м. сто...а
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:158)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:305)
at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:3718)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:2583)
at oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:1605)
at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:236)
at org.hibernate.type.IntegerType.get(IntegerType.java:28)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2031)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1371)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1299)
at org.hibernate.loader.Loader.getRow(Loader.java:1197)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:568)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2144)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
at org.hibernate.loader.Loader.list(Loader.java:2023)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:150)
at test.TestDAOImpl$2.doInHibernate(TestDAOImpl.java:173)
Name and version of the database you are using:
Oracle Database 10g
The generated SQL (show_sql=true):
select t.ID as ID0_0_ from Test t where connect_by_isleaf=1 start with t.ID=2 connect by prior t.ID=t.PARENT_ID order by t.KLASSE
|