org.hibernate.exception.SQLGrammarException:无法初始化集合:

时间:2014-09-30 18:15:21

标签: hibernate

这是完整的堆栈跟踪。我检查了他们正确映射的所有表和列。 Hibernate会自动创建连接表吗?因为我不想要那个表吗?我也无法访问在DB中创建表

19:06:01,444 WARN  [org.hibernate.util.JDBCExceptionReporter] (ajp--0.0.0.0-8016-3) SQL Error: 972, SQLState: 42000
19:06:01,444 ERROR [org.hibernate.util.JDBCExceptionReporter] (ajp--0.0.0.0-8016-3) ORA-00972: identifier is too long

19:06:01,459 ERROR [stderr] (ajp--0.0.0.0-8016-3) org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.lv.rs.accessautomation.common.vo.QuoteUserInfoVO.quoteUserRoleVO#component[ssoId,quoteId]{quoteId=1, ssoId=LOPJS}]
19:06:01,460 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
19:06:01,460 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
19:06:01,460 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.hibernate.loader.Loader.loadCollection(Loader.java:2173)
19:06:01,460 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:62)
19:06:01,460 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:627)
19:06:01,460 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
19:06:01,461 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1863)
19:06:01,461 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:369)
19:06:01,461 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:111)
19:06:01,461 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.hibernate.collection.PersistentSet.toString(PersistentSet.java:332)
19:06:01,461 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at java.lang.String.valueOf(String.java:2854)
19:06:01,461 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at java.lang.StringBuilder.append(StringBuilder.java:128)
19:06:01,462 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at com.lv.rs.accessautomation.common.vo.QuoteUserInfoVO.toString(QuoteUserInfoVO.java:85)
19:06:01,462 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at java.lang.String.valueOf(String.java:2854)
19:06:01,462 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at java.lang.StringBuilder.append(StringBuilder.java:128)
19:06:01,462 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at java.util.AbstractCollection.toString(AbstractCollection.java:450)
19:06:01,462 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at java.lang.String.valueOf(String.java:2854)
19:06:01,462 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at java.lang.StringBuilder.append(StringBuilder.java:128)
19:06:01,462 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at com.lv.rs.accessautomation.business.service.impl.AccessServiceImpl.saveQuotesUser(AccessServiceImpl.java:138)
19:06:01,463 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at com.lv.rs.accessautomation.business.service.impl.AccessServiceImpl.saveUser(AccessServiceImpl.java:114)
19:06:01,463 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
19:06:01,463 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
19:06:01,463 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
19:06:01,463 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at java.lang.reflect.Method.invoke(Method.java:601)
19:06:01,463 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
19:06:01,463 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
19:06:01,464 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
19:06:01,464 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
19:06:01,464 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
19:06:01,464 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
19:06:01,464 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at $Proxy252.saveUser(Unknown Source)
19:06:01,464 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at com.lv.rs.accessautomation.view.controller.AutomationController.doActions(AutomationController.java:74)
19:06:01,465 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
19:06:01,465 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
19:06:01,465 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
19:06:01,465 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at java.lang.reflect.Method.invoke(Method.java:601)
19:06:01,465 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
19:06:01,465 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
19:06:01,466 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
19:06:01,466 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
19:06:01,466 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
19:06:01,466 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
19:06:01,466 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
19:06:01,466 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
19:06:01,467 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
19:06:01,467 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
19:06:01,467 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
19:06:01,467 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
19:06:01,467 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
19:06:01,467 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
19:06:01,468 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
19:06:01,468 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
19:06:01,468 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
19:06:01,468 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
19:06:01,468 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:505)
19:06:01,468 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:445)
19:06:01,469 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
19:06:01,469 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at java.lang.Thread.run(Thread.java:722)
19:06:01,469 ERROR [stderr] (ajp--0.0.0.0-8016-3) Caused by: java.sql.SQLSyntaxErrorException: ORA-00972: identifier is too long
19:06:01,469 ERROR [stderr] (ajp--0.0.0.0-8016-3) 
19:06:01,469 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
19:06:01,469 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
19:06:01,469 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837)
19:06:01,469 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
19:06:01,470 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
19:06:01,470 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523)
19:06:01,470 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
19:06:01,470 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:862)
19:06:01,470 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1153)
19:06:01,470 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1275)
19:06:01,470 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3576)
19:06:01,471 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3620)
19:06:01,471 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1491)
19:06:01,471 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
19:06:01,471 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
19:06:01,471 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.hibernate.loader.Loader.doQuery(Loader.java:802)
19:06:01,471 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
19:06:01,472 ERROR [stderr] (ajp--0.0.0.0-8016-3) 	at org.hibernate.loader.Loader.loadCollection(Loader.java:2166)

我在两个表之间建立了多个可能的关系,但我不希望生成任何字段,如主键或具有连接表。但是如果我运行我的代码,则会得到belwo异常。

19:06:01,444 WARN  [org.hibernate.util.JDBCExceptionReporter] (ajp--0.0.0.0-8016-3) SQL Error: 972, SQLState: 42000
19:06:01,444 ERROR [org.hibernate.util.JDBCExceptionReporter] (ajp--0.0.0.0-8016-3) ORA-00972: identifier is too long

19:06:01,459 ERROR [stderr] (ajp--0.0.0.0-8016-3) org.hibernate.exception.SQLGrammarException: could not initialize a collection:

/**
 * 
 */


import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

   
@Entity
@Table(name="QT_USER_ROLE")
public class QuoteUserRoleVO implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Id
	@Column(name = "SSO_ID")
	private String ssoId;
	@Id
	@Column(name = "QUOTE_TYPE_ID")
	private int quoteId;
	@Id
	@Column(name = "ROLE_ID")
	private int roleId;
	@Column(name = "ADMINISTRATOR_FLG")
	private String adminFlg;
	@Column(name = "UNDERWRITER_FLG")
	private String underWriterFlg;
	
	@ManyToMany(mappedBy="quoteUserRoleVO")
	private Set<QuoteUserInfoVO> quoteUserInfoVO = new HashSet<QuoteUserInfoVO>();
	
	public String getSsoId() {
		return ssoId;
	}
	public void setSsoId(String ssoId) {
		this.ssoId = ssoId;
	}
	public int getQuoteId() {
		return quoteId;
	}
	public void setQuoteId(int quoteId) {
		this.quoteId = quoteId;
	}
	public int getRoleId() {
		return roleId;
	}
	public void setRoleId(int roleId) {
		this.roleId = roleId;
	}
	public String getAdminFlg() {
		return adminFlg;
	}
	public void setAdminFlg(String adminFlg) {
		this.adminFlg = adminFlg;
	}
	public String getUnderWriterFlg() {
		return underWriterFlg;
	}
	public void setUnderWriterFlg(String underWriterFlg) {
		this.underWriterFlg = underWriterFlg;
	}
	public Set<QuoteUserInfoVO> getQuoteUserInfoVO() {
		return quoteUserInfoVO;
	}
	public void setQuoteUserInfoVO(Set<QuoteUserInfoVO> quoteUserInfoVO) {
		this.quoteUserInfoVO = quoteUserInfoVO;
	}
	@Override
	public String toString() {
		return "QuoteUserRoleVO [ssoId=" + ssoId + ", quoteId=" + quoteId
				+ ", roleId=" + roleId + ", adminFlg=" + adminFlg
				+ ", underWriterFlg=" + underWriterFlg + "]";
	}
	
	

}
/**
 * 
 */


import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;


@Entity
@Table(name="QT_USER_INFORMATION")
public class QuoteUserInfoVO implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Id
	@Column(name = "SSO_ID")
	private String ssoId;
	@Id
	@Column(name = "QUOTE_TYPE_ID")
	private int quoteId;
	@Column(name = "FORENAME_TXT")
	private String forename;
	@Column(name = "SURNAME_TXT")
	private String surname;
	@Column(name = "ACTIVE_FLG")
	private String activeFlag;
	
	@ManyToMany(cascade = {CascadeType.ALL})
	private Set<QuoteUserRoleVO> quoteUserRoleVO = new HashSet<QuoteUserRoleVO>();
	
	public String getSsoId() {
		return ssoId;
	}
	public void setSsoId(String ssoId) {
		this.ssoId = ssoId;
	}
	public int getQuoteId() {
		return quoteId;
	}
	public void setQuoteId(int quoteId) {
		this.quoteId = quoteId;
	}
	public String getForename() {
		return forename;
	}
	public void setForename(String forename) {
		this.forename = forename;
	}
	public String getSurname() {
		return surname;
	}
	public void setSurname(String surname) {
		this.surname = surname;
	}
	public String getActiveFlag() {
		return activeFlag;
	}
	public void setActiveFlag(String activeFlag) {
		this.activeFlag = activeFlag;
	}
	public Set<QuoteUserRoleVO> getQuoteUserRoleVO() {
		return quoteUserRoleVO;
	}
	public void setQuoteUserRoleVO(Set<QuoteUserRoleVO> quoteUserRoleVO) {
		this.quoteUserRoleVO = quoteUserRoleVO;
	}
	@Override
	public String toString() {
		return "QuoteUserInfoVO [ssoId=" + ssoId + ", quoteId=" + quoteId
				+ ", forename=" + forename + ", surname=" + surname
				+ ", activeFlag=" + activeFlag + ", quoteUserRoleVO="
				+ quoteUserRoleVO + "]";
	}
	
	

}

1 个答案:

答案 0 :(得分:0)

这里的根本问题似乎是&#34; ORA-00972:标识符太长错误&#34;。由于您尝试使用hibernate orm访问oracle db,因此hibernate生成的隐式sql可能具有长度为&gt;的标识符。 30.由于您对上述域对象中的某些字段具有@ManyToMany关联,因此为该连接生成的sql可能具有更大的长度标识符。

要解决此问题,您可以尝试使用较小的标识符名称,因为联接通常会创建<TABLE1_NAME>_<FIELD1_NAME>_<TABLE2_NAME>_<FIELD2_NAME>的标识符,这显然超过了上述域实体的长度。

解决此问题的另一种方法是通过在hibernate中实现NamingStratefy接口(javadocs:https://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/cfg/class-use/NamingStrategy.html)来使用CustomerNamingStrategy进行休眠。

对于Oracle特定的自定义命名策略,请查看https://code.google.com/p/hibernate-naming-strategy-for-oracle/downloads/list上的示例代码。

希望这会有所帮助!!