I'm trying to map a java.util.Map<Integer,Embeddable> and am not having any luck. I've pored through the docs and the unit tests, and while it seems like this should be supported, I can't find an example of how to do it appropriately. Perhaps it is foreboding that there is no unit test that does this.
What's happening is that it's examining the component type correctly to deduce the columns in the table, but then for some reason it's adding a "value" column to the SQL. There's no such column in the table and no hint of a "value" property anywhere in the code. I've tried lots of variations to get rid of this, but it's in the SQL every time hibernate tries to fetch the collection.
Artefacts below. If anyone can help me, I'd really appreciate it. We're not on quite the latest releases, but I can't find anything on the JIRA changelog that would indicate this is fixed, and I don't want to go through the whole upgrade to find out it's the same!
Hibernate version:
Hibernate 3.2 cr2
Hibernate Annotations 3.2.0.CR1
Mapping documents:
Code:
@Entity
public class TraceInfo implements Comparable<TraceInfo> {
@Id @GeneratedValue(generator = "GenTraceInfo")
@GenericGenerator(name="GenTraceInfo", strategy="sequence", parameters=@Parameter(name="sequence", value="sq_trace_info"))
private Long traceInfoId;
....
// A map of Phred scores where the key is the phred score bucket
@CollectionOfElements @Embedded
@JoinTable(name="trace_phred_score", joinColumns=@JoinColumn(name="traceInfoId"))
@org.hibernate.annotations.MapKey(columns=@Column(name="phredScoreBin"))
@Column(name="phredScoreBin")
private Map<Integer,TraceQualityInfo> phredScoreCounts = new HashMap<Integer,TraceQualityInfo>();
// getters and setters omitted for brevity
}
@Embeddable
public class TraceQualityInfo {
@Basic private int phredScoreBin;
@Basic private Integer ampliconCount;
@Basic private Integer goodQualityRegionCount;
@Basic private Integer atrCount;
// getters and setters omitted for brevity
}
Code between sessionFactory.openSession() and session.close():TraceInfo ti = (TraceInfo) session.get(TraceInfo.class, 2732391);
ti.getPhredScoreCounts().size();
Full stack trace of any exception that occurs:The stack trace is captured from when a lot of TraceInfo objects were in memory and it was batching the fetch of the collection.
org.hibernate.exception.SQLGrammarException: could not initialize a collection batch: [edu.mit.broad.reseq.datavo.TraceInfo.phredScoreCounts#<2732391, 2732305, 2732613, 2732486, 2732584, 2732427, 2732292, 2732970, 2732324, 2732452, 2732439, 2732446, 2732441, 2732856, 2732388, 2732383, 2732668, 2732877, 2732437, 2732284, 2732390, 2732297, 2732936, 2732961, 2732294, 2732440, 2732566, 2732303, 2732545, 2732675, 2732475, 2732272, 2732316, 2732561, 2732415, 2732425, 2732462, 2732406, 2732394, 2732287, 2732493, 2732321, 2732713, 2732813, 2732295, 2732285, 2732505, 2732283, 2732315, 2732402, 2732837, 2732448, 2732574, 2732862, 2732299, 2732477, 2732451, 2732453, 2732730, 2732711, 2732399, 2732392, 2732868, 2732381, 2732286, 2732746, 2732588, 2732313, 2732603, 2732278, 2732751, 2732300, 2732385, 2732523, 2732481, 2732314, 2732704, 2732280, 2732459, 2732693, 2732323, 2732293, 2732521, 2732583, 2732637, 2732395, 2732309, 2732826, 2732431, 2732510, 2732355, 2732317, 2732302, 2732529, 2732312, 2732420, 2732783, 2732422, 2732598, 2732901>]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadCollectionBatch(Loader.java:1964)
at org.hibernate.loader.collection.BatchingCollectionInitializer.initialize(BatchingCollectionInitializer.java:47)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:541)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1705)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:109)
at org.hibernate.collection.PersistentMap.size(PersistentMap.java:95)
at java.util.TreeMap.putAll(TreeMap.java:314)
at java.util.TreeMap.<init>(TreeMap.java:156)
at edu.mit.broad.reseq.datavo.TraceInfo.getSortedPhredScoreCounts(TraceInfo.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.commons.el.ArraySuffix.evaluate(ArraySuffix.java:314)
at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
at org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:263)
at org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:190)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:932)
at org.apache.jsp.tiles.pcr.pcr_005fwell_005fdetail_jsp._jspx_meth_c_forEach_0(pcr_005fwell_005fdetail_jsp.java:1603)
at org.apache.jsp.tiles.pcr.pcr_005fwell_005fdetail_jsp._jspx_meth_display_column_7(pcr_005fwell_005fdetail_jsp.java:1566)
at org.apache.jsp.tiles.pcr.pcr_005fwell_005fdetail_jsp._jspService(pcr_005fwell_005fdetail_jsp.java:424)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at edu.mit.broad.reseq.web.ReSeqSecurityFilter.doFilter(ReSeqSecurityFilter.java:103)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at edu.mit.broad.mpgcore.web.MPGTransactionFilter.doFilter(MPGTransactionFilter.java:40)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:181)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.valves.FastCommonAccessLogValve.invoke(FastCommonAccessLogValve.java:495)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:613)
Caused by: java.sql.SQLException: ORA-00904: "PHREDSCORE0_"."VALUE": 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.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:236)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadCollectionBatch(Loader.java:1957)
... 60 more
Name and version of the database you are using:Oracle 10G on Linux
The generated SQL (show_sql=true):Code:
select phredscore0_.trace_info_id as trace1_0_,
phredscore0_.phred_score_bin as phred2_0_,
phredscore0_.amplicon_count as amplicon3_0_,
phredscore0_.good_quality_region_count as good4_0_,
phredscore0_.atr_count as atr5_0_,
phredscore0_.value as value0_
from trace_phred_score phredscore0_
where phredscore0_.trace_info_id = ?