【发布时间】:2021-06-26 15:17:10
【问题描述】:
我收到此错误:
信息:HHH000205:从资源 hibernate.properties 加载的属性:{hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.dialect=org.hibernate.dialect.Oracle8iDialect, hibernate.connection.password=** **, hibernate.connection.username=myUserName, hibernate.connection.url=jdbc:oracle:thin:@//myHost:1521/mySID, hibernate.bytecode.use_reflection_optimizer=false, show_sql=true}
org.hibernate.HibernateException:访问 stax 流时出错 在 org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:107) 在 org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:65) 在 org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57) 在 org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:165) 在 org.hibernate.cfg.Configuration.configure(Configuration.java:258) 在 gradletests.HibernateUtils.getSessionFactory(HibernateUtils.java:15) 在 gradlettests.MainTest.main(MainTest.java:14) 引起:javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1] 消息:prolog 中不允许有内容。 在 java.xml/com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:652) 在 java.xml/com.sun.xml.internal.stream.XMLEventReaderImpl.peek(XMLEventReaderImpl.java:277) 在 org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:103) ... 6 更多
在尝试打开这样的会话时:
private static SessionFactory factory;
private static boolean isInitialized = false;
public static synchronized SessionFactory getSessionFactory() {
if (!isInitialized) {
factory = new Configuration().configure("hibernate.properties").
addAnnotatedClass(Myclass.class).
buildSessionFactory();
isInitialized = true;
}
return factory;
}
显然,我的属性文件是关于输出读取的:
信息:HHH000205:从资源 hibernate.properties 加载的属性:{hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.dialect=org.hibernate.dialect.Oracle8iDialect, hibernate.connection.password=****, hibernate.connection.username=myUserName, hibernate.connection.url=jdbc:oracle:thin:@//myHost:1521/mySID, hibernate.bytecode.use_reflection_optimizer=false, show_sql=true}
hibernate.properties 看起来像这样:
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.connection.url=jdbc:oracle:thin:@//myHost:1521/mySID
hibernate.connection.username=myUserName
hibernate.connection.password=myPassword
hibernate.dialect=org.hibernate.dialect.Oracle8iDialect
show_sql=true
我的 build.gradle 导入那些:
implementation group: 'org.springframework', name: 'spring-context', version: '5.1.4.RELEASE'
implementation group: 'org.springframework', name: 'spring-orm', version: '5.1.4.RELEASE'
implementation group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.1.4.RELEASE'
implementation group: 'org.hibernate', name: 'hibernate-core', version: '5.4.1.Final'
implementation group: 'com.oracle.database.jdbc', name: 'ojdbc8', version: '21.1.0.0'
第二部分的错误:
原因:javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1] 消息:prolog 中不允许内容。在 java.xml/com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:652) 在 java.xml/com.sun.xml.internal.stream.XMLEventReaderImpl.peek(XMLEventReaderImpl. java:277) 在 org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:103) ... 6 更多
指的是文件的行和列,它是hibernate.properties,我知道是因为如果我在文件的开头添加一个返回,它会导致第2行和第1列而不是1,1 .
我不明白,因为它似乎第一次正确读取文件,然后像在等待 xml 格式一样崩溃。
我以为我没有正确加载班级中的属性文件,但我没有找到有关如何加载它的任何信息。有什么想法吗?
【问题讨论】:
标签: java hibernate jpa configuration