java - Hibernate set up -
i writing first hibernate program, unable connect database
details:db: oracle 11g version 2
hibernate: 4.3.7.
could please verify config file:
hibernate.cfg.xml:
<?xml version="1.0" encoding="utf-8"?> <hibernate-configuration xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.hibernate.org/xsd/ hibernate-configuration hibernate-configuration- 4.0.xsd" xmlns="http://www.hibernate.org/xsd/hibernate-configuration"> <session-factory> <!-- database connection settings --> <property name="connection.driver_class">oracle.jdbc.oracledriver</property> <property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property> <property name="connection.username">sys</property> <property name="connection.password">admin123</property> <!-- jdbc connection pool (use built-in) --> <property name="connection.pool_size">1</property> <!-- sql dialect --> <property name="dialect">org.hibernate.dialect.oracle10gdialect</property> <!-- enable hibernate's automatic session context management --> <property name="current_session_context_class">thread</property> <!-- disable second-level cache --> <property name="cache.provider_class">org.hibernate.cache.internal.nocacheprovider</property> <!-- echo executed sql stdout --> <property name="show_sql">true</property> <!-- drop , re-create database schema on startup --> <property name="hbm2ddl.auto">create</property> <!-- names annotated entity class --> <mapping class="com.hp.dto.userdetails"/> <mapping resource="org/hibernate/tutorial/domain/event.hbm.xml"/> </session-factory> </hibernate-configuration>
java class:
import javax.persistence.entity; import javax.persistence.id; @entity public class userdetails { @id private int userid; private string username; public int getuserid() { return userid; } public void setuserid(int userid) { this.userid = userid; } public string getusername() { return username; } public void setusername(string username) { this.username = username; } }
manager class:
public class hibernatetest { public static void main(string[] args){ userdetails user=new userdetails(); user.setuserid(1); user.setusername("first user"); sessionfactory sessionfactory=new configuration().configure().buildsessionfactory(); session session= sessionfactory.opensession(); session.begintransaction(); session.save(user); session.gettransaction().commit(); } }
exception:
info: hhh000043: configuring resource: /hibernate.cfg.xml dec 16, 2014 5:13:24 pm org.hibernate.cfg.configuration getconfigurationinputstream info: hhh000040: configuration resource: /hibernate.cfg.xml exception in thread "main" org.hibernate.mappingexception: invalid configuration @ org.hibernate.cfg.configuration.doconfigure(configuration.java:2160) @ org.hibernate.cfg.configuration.configure(configuration.java:2077) @ org.hibernate.cfg.configuration.configure(configuration.java:2056) @ com.hp.hibernate.hibernatetest.main(hibernatetest.java:18) caused by: org.xml.sax.saxparseexception; linenumber: 2; columnnumber: 25; document invalid: no grammar found. @ com.sun.org.apache.xerces.internal.util.errorhandlerwrapper.createsaxparseexception(errorhandlerwrapper.java:198) @ com.sun.org.apache.xerces.internal.util.errorhandlerwrapper.error(errorhandlerwrapper.java:134) @ com.sun.org.apache.xerces.internal.impl.xmlerrorreporter.reporterror(xmlerrorreporter.java:437) @ com.sun.org.apache.xerces.internal.impl.xmlerrorreporter.reporterror(xmlerrorreporter.java:368) @ com.sun.org.apache.xerces.internal.impl.xmlerrorreporter.reporterror(xmlerrorreporter.java:325) @ com.sun.org.apache.xerces.internal.impl.xmlnsdocumentscannerimpl.scanstartelement(xmlnsdocumentscannerimpl.java:228) @ com.sun.org.apache.xerces.internal.impl.xmlnsdocumentscannerimpl$nscontentdriver.scanrootelementhook(xmlnsdocumentscannerimpl.java:605) @ com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl$fragmentcontentdriver.next(xmldocumentfragmentscannerimpl.java:3138) @ com.sun.org.apache.xerces.internal.impl.xmldocumentscannerimpl$prologdriver.next(xmldocumentscannerimpl.java:880) @ com.sun.org.apache.xerces.internal.impl.xmldocumentscannerimpl.next(xmldocumentscannerimpl.java:606) @ com.sun.org.apache.xerces.internal.impl.xmlnsdocumentscannerimpl.next(xmlnsdocumentscannerimpl.java:117) @ com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl.scandocument(xmldocumentfragmentscannerimpl.java:510) @ com.sun.org.apache.xerces.internal.parsers.xml11configuration.parse(xml11configuration.java:848) @ com.sun.org.apache.xerces.internal.parsers.xml11configuration.parse(xml11configuration.java:777) @ com.sun.org.apache.xerces.internal.parsers.xmlparser.parse(xmlparser.java:141) @ com.sun.org.apache.xerces.internal.parsers.abstractsaxparser.parse(abstractsaxparser.java:1213) @ com.sun.org.apache.xerces.internal.jaxp.saxparserimpl$jaxpsaxparser.parse(saxparserimpl.java:648) @ org.dom4j.io.saxreader.read(saxreader.java:465) @ org.hibernate.cfg.configuration.doconfigure(configuration.java:2157) ... 3 more
remove schema declaration:
<hibernate-configuration xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd" xmlns="http://www.hibernate.org/xsd/hibernate-configuration">
so is:
<hibernate-configuration>
if want schema validation, use dtd instead:
Comments
Post a Comment