线程" main"中的Hibernate Mapping异常配置时由无效映射引起的java.lang.ExceptionInInitializerError

时间:2017-07-12 16:24:35

标签: java hibernate hibernate-mapping

我正在尝试通过互联网找到的hibernate set映射示例,而我在运行HibernateUtil java类时面临以下问题。但是,在编译类和pojo文件时没有遇到任何问题。

Jul 12, 2017 8:42:02 PM 
org.hibernate.annotations.common.reflection.java.JavaReflectionManager<clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
Jul 12, 2017 8:42:02 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.1.Final}
Jul 12, 2017 8:42:02 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jul 12, 2017 8:42:02 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jul 12, 2017 8:42:02 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Jul 12, 2017 8:42:02 PM org.hibernate.cfg.ConfigurationgetConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Jul 12, 2017 8:42:02 PM org.hibernate.internal.util.xml.DTDEntityResolverresolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
Jul 12, 2017 8:42:02 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: PoJo/Employee.hbm.xml
Jul 12, 2017 8:42:02 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: PoJo/Certificates.hbm.xml
Jul 12, 2017 8:42:02 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Jul 12, 2017 8:42:03 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderI pl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Jul 12, 2017 8:42:03 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderI pl buildCreator
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/empl]
Jul 12, 2017 8:42:03 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=root, password=****}
Jul 12, 2017 8:42:03 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
Jul 12, 2017 8:42:03 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Jul 12, 2017 8:42:03 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
Initial SessionFactory creation failed.org.hibernate.InvalidMappingException: Could not parse mapping document from resource PoJo/Employee.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at HibSetMap.main(HibSetMap.java:27)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource PoJo/Employee.hbm.xml
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3764)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3753)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3741)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
at HibSetMap.main(HibSetMap.java:23)
Caused by: org.hibernate.MappingException: column attribute may not be used together with <column> subelement
at org.hibernate.cfg.HbmBinder.bindColumns(HbmBinder.java:1117)
at org.hibernate.cfg.HbmBinder.bindColumnsOrFormula(HbmBinder.java:1627)
at org.hibernate.cfg.HbmBinder.bindSimpleValue(HbmBinder.java:1193)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:443)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:386)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:326)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:177)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3761)
... 6 more

这是我的employee.hbm.xml

&#13;
&#13;
<hibernate-mapping>
    <class name="PoJo.Employee" table="employee" catalog="empl" optimistic-lock="version">
        <meta attribute="class-discription">
            This class contains the employee details.
        </meta> 
        <id name="id" type="int" column="id">
            <column name="id" />
            <generator class="native" />
        </id>
        
        <set name="certificates" cascade="all">
            <key column="employeeId"/>
            <one-to-many class="Certificates"/>
        </set>
        <property name="fname" type="string" column="fname">
            <column name="fname" length="20" />
        </property>
        <property name="lname" type="string" column="lname">
            <column name="lname" length="20" />
        </property>
        <property name="salary" type="int" column= "salary">
            <column name="salary" />
        </property>
    </class>
</hibernate-mapping>
&#13;
&#13;
&#13;

而且,这是我遇到问题的代码部分

public class HibSetMap {

private static SessionFactory sessionFactory;


public static void main(String[] args) {

try {
        // Create the SessionFactory from standard (hibernate.cfg.xml) 
        // config file.
        sessionFactory = new Configuration().configure().buildSessionFactory();
    } catch (Throwable ex) {
        // Log the exception. 
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
    }

请帮助!!

1 个答案:

答案 0 :(得分:0)

您是否尝试删除子元素或属性列=&#34;薪水(适用于所有专业人士)

好像你不能同时拥有