I have a mapped entity class (ItemStateImpl ) that has a primary key composed of 3 fields.
I used the @IdClass anotation on the entity class and created a
pk class with the @Embeddable anotation. Both classes are detailed below.
My entity class has a OneToOne refernce to the same table where each item has a refernece to it's previous and next items
When I preform the following query:
EntityManager em = EmUtil.getEntityManager(); itemStates = em.createQuery("Select itemState from ItemStateImpl as itemState").getResultList();
I get the exception detailed below.
It looks like Hibernate is ignoring the actual database column names I defined in the @Column anotation and uses the attribute name instead.
java.sql.SQLException: ORA-00904: "ITEMSTATE0_"."M_ITEMYEAR": invalid identifier -
The DB filed name is ITEM_YEAR and the property name is m_itamYear
I tried putting the @Column anotation on the entity class, the pk class and both classes but none seems to work.
I am using hibernate-3.2, hibernate-annotations-3.3.1.GA, hibernate-entitymanager-3.3.2.GA
below is the log outout:
11:38:34,812 DEBUG QueryTranslatorImpl:246 - parse() - HQL: Select itemState from
comp.proj.gajcfgrcommon.entities.logical.impl.ItemStateImpl as itemState
11:38:34,843 DEBUG AST:266 - --- HQL AST ---
\-[QUERY] 'query'
\-[SELECT_FROM] 'SELECT_FROM'
+-[FROM] 'from'
| \-[RANGE] 'RANGE'
| +-[DOT] '.'
| | +-[DOT] '.'
| | | +-[DOT] '.'
| | | | +-[DOT] '.'
| | | | | +-[DOT] '.'
| | | | | | +-[DOT] '.'
| | | | | | | +-[IDENT] 'comp'
| | | | | | | \-[IDENT] 'proj'
| | | | | | \-[IDENT] 'gajcfgrcommon'
| | | | | \-[IDENT] 'entities'
| | | | \-[IDENT] 'logical'
| | | \-[IDENT] 'impl'
| | \-[IDENT] 'ItemStateImpl'
| \-[ALIAS] 'itemState'
\-[SELECT] 'Select'
\-[IDENT] 'itemState'
11:38:34,843 DEBUG ErrorCounter:68 - throwQueryException() : no errors
11:38:34,921 DEBUG HqlSqlBaseWalker:111 - select << begin [level=1, statement=select]
11:38:34,953 DEBUG FromElement:108 - FromClause{level=1} : comp.proj.gajcfgrcommon.entities.logical.impl.ItemStateImpl
(itemState) -> itemstate0_
11:38:34,953 DEBUG FromReferenceNode:51 - Resolved : itemState -> (itemstate0_.m_itemCode, itemstate0_.m_itemInstance,
itemstate0_.m_itemYear)
11:38:34,968 DEBUG HqlSqlBaseWalker:117 - select : finishing up [level=1, statement=select]
11:38:34,968 DEBUG HqlSqlWalker:509 - processQuery() : ( SELECT ( {select clause} (itemstate0_.m_itemCode,
itemstate0_.m_itemInstance, itemstate0_.m_itemYear) ) ( FromClause{level=1} ADJ1_ITEM_STATE itemstate0_ ) )
11:38:35,078 DEBUG JoinProcessor:148 - Using FROM fragment [ADJ1_ITEM_STATE itemstate0_]
11:38:35,078 DEBUG HqlSqlBaseWalker:123 - select >> end [level=1, statement=select]
11:38:35,078 DEBUG AST:232 - --- SQL AST ---
\-[SELECT] QueryNode: 'SELECT' querySpaces (ADJ1_ITEM_STATE)
+-[SELECT_CLAUSE] SelectClause: '{select clause}'
| +-[ALIAS_REF] IdentNode: 'itemstate0_.m_itemCode as m1_9_, itemstate0_.m_itemInstance as m2_9_, itemstate0_.m_itemYear
as m3_9_' {alias=itemState, className=comp.proj.gajcfgrcommon.entities.logical.impl.ItemStateImpl, tableAlias=itemstate0_}
| \-[SQL_TOKEN] SqlFragment: 'itemstate0_.APPLICATION_ID as APPLICAT4_9_, itemstate0_.SYS_CREATION_DATE as SYS5_9_,
itemstate0_.SYS_UPDATE_DATE as SYS6_9_, itemstate0_.DL_UPDATE_STAMP as DL7_9_, itemstate0_.CLOSE_DATE as CLOSE8_9_,
itemstate0_.FIRST_DATE as FIRST9_9_, itemstate0_.LOCKED_FOR_NEW as LOCKED10_9_, itemstate0_.LOCKED_FOR_UPDATE as LOCKED11_9_,
itemstate0_.MAINTENANCE_STATUS as MAINTEN12_9_, itemstate0_.ITEM_CODE as ITEM13_9_, itemstate0_.ITEM_INSTANCE as
ITEM14_9_, itemstate0_.ITEM_YEAR as ITEM15_9_'
\-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=
[itemState], fromElementByTableAlias=[itemstate0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[],
impliedElements=[]}
\-[FROM_FRAGMENT] FromElement: 'ADJ1_ITEM_STATE itemstate0_' FromElement{explicit,not a collection join,not a fetch
join,fetch non-lazy
properties,classAlias=itemState,role=null,tableName=ADJ1_ITEM_STATE,tableAlias=itemstate0_,origin=null,colums=
{,className=comp.proj.gajcfgrcommon.entities.logical.impl.ItemStateImpl}}
11:38:35,078 DEBUG ErrorCounter:68 - throwQueryException() : no errors
11:38:35,109 DEBUG QueryTranslatorImpl:216 - HQL: Select itemState from
comp.proj.gajcfgrcommon.entities.logical.impl.ItemStateImpl as itemState
11:38:35,109 DEBUG QueryTranslatorImpl:217 - SQL: select itemstate0_.m_itemCode as m1_9_, itemstate0_.m_itemInstance as
m2_9_, itemstate0_.m_itemYear as m3_9_, itemstate0_.APPLICATION_ID as APPLICAT4_9_, itemstate0_.SYS_CREATION_DATE as SYS5_9_,
itemstate0_.SYS_UPDATE_DATE as SYS6_9_, itemstate0_.DL_UPDATE_STAMP as DL7_9_, itemstate0_.CLOSE_DATE as CLOSE8_9_,
itemstate0_.FIRST_DATE as FIRST9_9_, itemstate0_.LOCKED_FOR_NEW as LOCKED10_9_, itemstate0_.LOCKED_FOR_UPDATE as LOCKED11_9_,
itemstate0_.MAINTENANCE_STATUS as MAINTEN12_9_, itemstate0_.ITEM_CODE as ITEM13_9_, itemstate0_.ITEM_INSTANCE as
ITEM14_9_, itemstate0_.ITEM_YEAR as ITEM15_9_ from ADJ1_ITEM_STATE itemstate0_
11:38:35,109 DEBUG ErrorCounter:68 - throwQueryException() : no errors
11:38:35,125 DEBUG HQLQueryPlan:269 - HQL param location recognition took 0 mills (Select itemState from ItemStateImpl as
itemState)
11:38:35,140 DEBUG QueryPlanCache:76 - located HQL query plan in cache (Select itemState from ItemStateImpl as itemState)
11:38:35,140 DEBUG HQLQueryPlan:150 - find: Select itemState from ItemStateImpl as itemState
11:38:35,140 DEBUG QueryParameters:277 - named parameters: {}
11:38:35,156 DEBUG AbstractBatcher:366 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
11:38:35,156 DEBUG ConnectionManager:421 - opening JDBC connection
11:38:35,156 DEBUG DriverManagerConnectionProvider:93 - total checked-out connections: 0
11:38:35,156 DEBUG DriverManagerConnectionProvider:99 - using pooled JDBC connection, pool size: 0
11:38:35,156 DEBUG SQL:401 - select itemstate0_.m_itemCode as m1_9_, itemstate0_.m_itemInstance as m2_9_,
itemstate0_.m_itemYear as m3_9_, itemstate0_.APPLICATION_ID as APPLICAT4_9_, itemstate0_.SYS_CREATION_DATE as SYS5_9_,
itemstate0_.SYS_UPDATE_DATE as SYS6_9_, itemstate0_.DL_UPDATE_STAMP as DL7_9_, itemstate0_.CLOSE_DATE as CLOSE8_9_,
itemstate0_.FIRST_DATE as FIRST9_9_, itemstate0_.LOCKED_FOR_NEW as LOCKED10_9_, itemstate0_.LOCKED_FOR_UPDATE as LOCKED11_9_,
itemstate0_.MAINTENANCE_STATUS as MAINTEN12_9_, itemstate0_.ITEM_CODE as ITEM13_9_, itemstate0_.ITEM_INSTANCE as
ITEM14_9_, itemstate0_.ITEM_YEAR as ITEM15_9_ from ADJ1_ITEM_STATE itemstate0_
11:38:35,156 DEBUG AbstractBatcher:484 - preparing statement
11:38:35,484 DEBUG AbstractBatcher:374 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
11:38:35,484 DEBUG AbstractBatcher:533 - closing statement
11:38:35,500 DEBUG ConnectionManager:404 - aggressively releasing JDBC connection
11:38:35,500 DEBUG ConnectionManager:441 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open
ResultSets: 0, globally: 0)]
11:38:35,500 DEBUG DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
11:38:35,500 DEBUG JDBCExceptionReporter:69 - could not execute query [select itemstate0_.m_itemCode as m1_9_,
itemstate0_.m_itemInstance as m2_9_, itemstate0_.m_itemYear as m3_9_, itemstate0_.APPLICATION_ID as APPLICAT4_9_,
itemstate0_.SYS_CREATION_DATE as SYS5_9_, itemstate0_.SYS_UPDATE_DATE as SYS6_9_, itemstate0_.DL_UPDATE_STAMP as DL7_9_,
itemstate0_.CLOSE_DATE as CLOSE8_9_, itemstate0_.FIRST_DATE as FIRST9_9_, itemstate0_.LOCKED_FOR_NEW as LOCKED10_9_,
itemstate0_.LOCKED_FOR_UPDATE as LOCKED11_9_, itemstate0_.MAINTENANCE_STATUS as MAINTEN12_9_, itemstate0_.ITEM_CODE as
ITEM13_9_, itemstate0_.ITEM_INSTANCE as ITEM14_9_, itemstate0_.ITEM_YEAR as ITEM15_9_ from ADJ1_ITEM_STATE itemstate0_]
java.sql.SQLException: ORA-00904: "ITEMSTATE0_"."M_ITEMYEAR": invalid identifier
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:799)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1039)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:839)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1132)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:65)
at comp.proj.cfgrbe.backend.EmPersistenceManager.getItemStates(EmPersistenceManager.java:475)
at comp.proj.cfgrbe.global.BusinessTester.listItemStaes(BusinessTester.java:48)
at comp.proj.cfgrbe.global.BusinessTester.main(BusinessTester.java:22)
11:38:35,515 WARN JDBCExceptionReporter:77 - SQL Error: 904, SQLState: 42000
11:38:35,515 ERROR JDBCExceptionReporter:78 - ORA-00904: "ITEMSTATE0_"."M_ITEMYEAR": invalid identifier
11:38:35,515 DEBUG JDBCContext:237 - after autocommit
11:38:35,515 DEBUG ConnectionManager:404 - aggressively releasing JDBC connection
11:38:35,515 DEBUG SessionImpl:422 - after transaction completion
11:38:35,515 DEBUG AbstractEntityManagerImpl:425 - mark transaction for rollback
--------------------------------------------
Impl class:
@Entity
@IdClass(ItemStatePK.class) //reference to the PK class
@Table(name="PRJ1_ITEM_STATE")
@AccessType("field")
public class ItemStateImpl extends AbstractEntity implements IItemState
{
@Id
@Column(name="ITEM_CODE")
private Long m_itemCode;
@Id
@Column(name="ITEM_INSTANCE")
private int m_itemInstance;
@Id
@Column(name="ITEM_YEAR")
private int m_itemYear;
@OneToOne
@JoinColumns ({
@JoinColumn(name="ITEM_CODE", referencedColumnName = "m_itemCode", insertable=false, updatable=false),
@JoinColumn(name="ITEM_INSTANCE", referencedColumnName = "m_itemInstance", insertable=false, updatable=false),
@JoinColumn(name="ITEM_YEAR", referencedColumnName = "m_itemYear",insertable=false, updatable=false)
})
private ItemStateImpl m_prevItemInst;
@OneToOne
@JoinColumns ({
@JoinColumn(name="ITEM_CODE", referencedColumnName = "m_itemCode", insertable=false, updatable=false),
@JoinColumn(name="ITEM_INSTANCE", referencedColumnName = "m_itemInstance", insertable=false, updatable=false),
@JoinColumn(name="ITEM_YEAR", referencedColumnName = "m_itemYear", insertable=false, updatable=false)
})
private ItemStateImpl m_nextItemInst;
@Column(name="FIRST_DATE")
private Date m_firstDate;
@Column(name="CLOSE_DATE")
private Date m_closeDate;
@Column(name="LOCKED_FOR_NEW")
private String m_lockedForNew;
@Column(name="LOCKED_FOR_UPDATE")
private String m_lockedForUpdate;
@Column(name="MAINTENANCE_STATUS")
private String m_maintenanceStatus;
public ItemStateImpl()
{
}
public Long getItemCode()
{
return m_itemCode;
}
public int getItemInstance()
{
return m_itemInstance;
}
/**
* @return the closeDate
*/
public Date getCloseDate()
{
return m_closeDate;
}
/**
* @return the itemYear
*/
public int getItemYear()
{
return m_itemYear;
}
/**
* @return the firstDate
*/
public Date getFirstDate()
{
return m_firstDate;
}
/**
* @return the lockedForNew
*/
public String getLockedForNew()
{
return m_lockedForNew;
}
/**
* @return the lockedForUpdate
*/
public String getLockedForUpdate()
{
return m_lockedForUpdate;
}
/**
* @return the maintenanceStatus
*/
public String getMaintenanceStatus()
{
return m_maintenanceStatus;
}
/**
* @return the prevItemInst
*/
public IItemState getPrevItemInst()
{
return m_prevItemInst;
}
/**
* @return the nextItemInst
*/
public IItemState getNextItemInst()
{
return m_nextItemInst;
}
@Transient
public EntityType getEntityType()
{
return EntityType.ITEM;
}
@Transient
public String getName()
{
//return m_pk.getItemCode().toString();
return m_itemCode.toString();
}
}
-------------------------------------------------------
pk class
@Embeddable
public class ItemStatePK implements Serializable
{
private Long m_itemCode;
private int m_itemInstance;
private int m_itemYear;
public itemStatePK()
{
}
@Column(name="Item_CODE")
public Long getitemCode()
{
return m_itemCode;
}
@Column(name="Item_INSTANCE")
public int getitemInstance()
{
return m_itemInstance;
}
@Column(name="Item_YEAR")
public int getitemYear()
{
return m_itemYear;
}
public void setitemCode(Long itemCode)
{
m_itemCode = itemCode;
}
public void setitemInstance(int itemInstance)
{
m_itemInstance = itemInstance;
}
public void setitemYear(int itemYear)
{
m_itemYear = itemYear;
}
---------------------------------------------------------------------------------
|