Monday 15 June 2015

java - How can I fix my /hibernate.cfg.xml file? -



java - How can I fix my /hibernate.cfg.xml file? -

i'm attempting follow tutorial: https://www.youtube.com/playlist?list=pl4aff701184976b25

i've gotten video 5 expecting see hibernate adding mysql database, i'm instead getting error. below hibernate.cfg.xml file.

slf4j: failed load class "org.slf4j.impl.staticloggerbinder". slf4j: defaulting no-operation (nop) logger implementation slf4j: see http://www.slf4j.org/codes.html#staticloggerbinder farther details. exception in thread "main" org.hibernate.hibernateexception: not parse configuration: /hibernate.cfg.xml @ org.hibernate.cfg.configuration.doconfigure(configuration.java:2246) @ org.hibernate.cfg.configuration.configure(configuration.java:2158) @ org.hibernate.cfg.configuration.configure(configuration.java:2137) @ org.koushik.hibernate.hibernatetest.main(hibernatetest.java:15) caused by: org.dom4j.documentexception: error on line 19 of document : open quote expected attribute "{1}" associated element type "name". nested exception: open quote expected attribute "{1}" associated element type "name". @ org.dom4j.io.saxreader.read(saxreader.java:482) @ org.hibernate.cfg.configuration.doconfigure(configuration.java:2238) ... 3 more <!doctype hibernate-configuration public "-//hibernate/hibernate configuration dtd//en" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- database connection settings --> <property name="connection.driver_class">com.mysql.jdbc.driver</property> <property name="connection.url">jdbc:mysql://localhost/hibernatedb</property> <property name="connection.username">root</property> <property name="connection.password">mysqlroot</property> <property name="connection.pool_size">1</property> <property name="dialect">org.hibernate.dialect.mysqldialect</property> <property name="cache.provider_class">org.hibernate.cache.nocacheprovider</property> <property name=show_sql>true</property> <property name="hbm2ddl.auto">create</property> <mapping class="org.koushik.javabrains.dto.userdetails" /> </session-factory> </hibernate-configuration>

what problem , how can go fixing it? can't tell if can't find file, or if syntactically wrong within it.

also, i'd grateful if point me towards working hibernate tutorials hibernate 4.3.7. i've found far mixture of broken/heavily out dated materials require installing past versions of hibernate larn from.

edit-------------------

i attempted validate in eclipse , error appears @ line 8 saying "the document type declaration root element type "hibernate-configuration" must end '>'." also, line line "connection..." doesn't appear in blue, , name part of property name doesn't appear in purple. feels syntax error can't seem find it.

edit 2------------------ here 2 files

userdetails.java

package org.koushik.javabrains.dto; import javax.persistence.entity; import javax.persistence.id; @entity public class userdetails { @id private int userid; private string username; public int getuserid() { homecoming userid; } public void setuserid(int userid) { this.userid = userid; } public string getusername() { homecoming username; } public void setusername(string username) { this.username = username; } }

hibernatetest.java

package org.koushik.hibernate; import org.hibernate.session; import org.hibernate.sessionfactory; import org.hibernate.cfg.configuration; import org.koushik.javabrains.dto.userdetails; 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(); } }

try this:

<?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-configuration public "-//hibernate/hibernate configuration dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">com.mysql.jdbc.driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost/hibernatedb</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">mysqlroot</property> <property name="hibernate.connection.pool_size">1</property> <property name="hibernate.dialect">org.hibernate.dialect.mysqldialect</property> <property name="hibernate.hbm2ddl.auto">create</property> <property name="hibernate.cache.provider_class">org.hibernate.cache.nocacheprovider</property> <property name="show_sql">true</property> <mapping class="org.koushik.javabrains.dto.userdetails" /> </session-factory> </hibernate-configuration>

java mysql hibernate orm hibernate.cfg.xml

No comments:

Post a Comment