对于我的工作,我必须首次在项目中使用 Hibernate 。实际上,一切都是由其他人设置的,现在我必须稍微扩展一下“查询”。 我们在 Eclipse 中运行 Tomcat v7.0 服务器, Quartz 框架用于每5分钟安排一次查询。然后,此查询由Hibernate执行/处理。我想我大部分时间都理解了,但正如我所说的:我在这里是个新手,所以这个问题真的很愚蠢,但是我无法使用Google / StackOverflow找到答案,所以就这样了。
由于我在hibernate的查询配置中修改了一些内容,因此我始终得到null
个结果。经过一番挣扎,我已经登录并运行了。这是启动Tomcat服务器时得到的(我认为)日志的相关部分:
30-apr-2012 11:02:32 org.hibernate.cfg.SettingsFactory buildSettings
WARNING: Could not obtain connection metadata
java.sql.SQLException: An SQLException was provoked by the following failure: java.lang.UnsupportedOperationException
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:62)
at com.mchange.v2.c3p0.impl.NewPooledConnection.handleThrowable(NewPooledConnection.java:369)
at com.mchange.v2.c3p0.impl.NewProxyDatabaseMetaData.getDatabaseMajorVersion(NewProxyDatabaseMetaData.java:3692)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:126)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:753)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:691)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1390)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1359)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:268)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1274)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1042)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:268)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1274)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1042)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)
at com.mh2o.dbase.manager.HibernateDaoManager.getInstance(HibernateDaoManager.java:17)
at com.mh2o.dbase.wbuserlist.WelcomeBoardMgr.<init>(WelcomeBoardMgr.java:11)
at com.mh2o.application.cache.welcomeboard.WelcomeCache.synchronize(WelcomeCache.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:283)
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:272)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)
at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: java.lang.UnsupportedOperationException
at sun.jdbc.odbc.JdbcOdbcDatabaseMetaData.getDatabaseMajorVersion(Unknown Source)
at com.mchange.v2.c3p0.impl.NewProxyDatabaseMetaData.getDatabaseMajorVersion(NewProxyDatabaseMetaData.java:3678)
... 53 more
30-apr-2012 11:02:32 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
因此,SQL中似乎存在错误。现在,我添加了一些文件,所以我想这就是出现错误的地方。数据库包含一个可以连接到已查询的表的表,这就是我所做的:
employeeavailablehours.hbm.xml (描述数据库中的表格):
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.mh2o.application.vo.planningview" schema="N_C">
<class name="EmployeeAvailableHours" table="WerknemersBeschikbareUr">
<id column="ID" name="id" type="string">
<generator class="native"/>
</id>
<property column="InitialenWerknemer" name="initial" generated="never" lazy="false" not-null="true" type="string"/>
<property column="Vanaf" name="from" generated="never" lazy="false" not-null="true" type="string"/>
<property column="Tot" name="to" generated="never" lazy="false" not-null="true" type="string"/>
<property column="Volgnummer" name="indexnumber" generated="never" lazy="false" not-null="true" type="string"/>
</class>
</hibernate-mapping>
employeeinfo.hbm.xml (已由其他人创建,由我修改为包含对上表的引用):
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.mh2o.application.vo.planningview" schema="N_C">
<class name="EmployeeInfo" table="WerknemersInfo">
<id column="ID" name="id" type="string">
<generator class="native"/>
</id>
<property column="Naam" name="name" generated="never" lazy="false" not-null="true" type="string"/>
<property column="InitialenWerknemer" name="initial" generated="never" lazy="false" not-null="true" type="string"/>
<set name="employeeavailablehours" table="WerknemersBeschikbareUr" inverse="false" lazy="false" fetch="select">
<key>
<column name="InitialenWerknemer" not-null="true" />
</key>
<one-to-many class="EmployeeAvailableHours" />
</set>
</class>
</hibernate-mapping>
当然,我在context.xml
中添加了新表employeePERhours,并创建了类来表示xml文件中命名的新表中的数据。此外,我已经编辑了代表现有表的类,也保留了对我添加的表的引用。我认为这不是出现错误的地方,查看异常,这就是为什么我不在这里包含这些类的Java源代码的原因。如果需要,我当然会。
如果你们需要更多信息,请询问,我会编辑我的问题。提前谢谢!
答案 0 :(得分:1)
事实证明我做错了一些事情:我用作外键的密钥根本不能用作外键。更改一个表与另一个表的连接位置的完整设置解决了问题。