Warning shown when creating hibernate.cfg.xml in Eclipse - java

Here is my code in file named hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.url">jdbc:mysql://localhost:3306/HeartJar</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<mapping resource="com/heartjar/bean/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
There was a waining saying Stream not availableat line 2
Although warnings don't have bad influences to my project.But Understanding how to solve the problem is useful for me,a beginner in JavaWeb.Thank you for your answer

Related

Eclipse fails to create hibernate hbm.xml file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/shop</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping class="hibernate_project.cust" file="cust"
package="hibernate_project" resource="hibernate_project/cust.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Source button missing from hibernate configuration XML file in eclipse

When I created a hibernate Configuration file, eclipse is not able to display the source code as there is no source button at the bottom of the page. I can able to navigate between Session Factory and Security whereas Source button is missing. How can fix this issue? I have attached the picture below for reference.
Hibernate Configuration XML File
make your own one and add the below:
fileName is: hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.org/dtd/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:3306/Book</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.pool_size">1</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="book.hbm.xml" />
</session-factory>
</hibernate-configuration>
And if you want to read more about it go here

Eclipse doesn't show correct tables in Hibernate config

I'm making a new project with Hibernate.
I have some problems configure hibernate correctly in my Eclipse environment.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.password">XXXXX</property>
<property name="hibernate.connection.url">jdbc:sqlserver://localhost/Framework</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.default_schema">Framework</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
My Eclipse environment only sees the master database instead of my Framework database. Can someone help me with this?
The database was not correctly configured. The user didn't have the correct permissions. After fixing this it works.

Cannot find the declaration of element 'hibernate-configuration' but it exists

This is my configuration:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-5.0.dtd">
<hibernate-configuration
xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/>
<mapping class="Mapping.AccountMap"
</session-factory>
</hibernate-configuration>
I read that i should change the "Doctype" and i did from other answers i have found, yet this error occurs:
Unable to perform unmarshalling at line number 8 and column 63 in RESOURCE hibernate.cfg.xml. Message: cvc-elt.1: Cannot find the declaration of element 'hibernate-configuration'.
Your dtd url is false ... seems like hibernate-configuration-5.0.dtd doesn't exist ... use this :
http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd
change the whole header :
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-5.0.dtd">
<hibernate-configuration
xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
TO
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
Try to add this header block. It works for me and also check parse error in your XML file.
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
Here i am posting some sample xml file may be it will help you.
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<!-- Names the annotated entity class -->
<mapping class="org.java.dto.UserDetails"/>
</session-factory>
</hibernate-configuration>

Hibernate, Could not parse configuration

I am new to Hibernate .... i tried this code but i got Could not parse configuration: NewFile.cfg.xml (name of .cfg.xml file)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- connection to oracle -->
<propertyname="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver </property>
<property name="hibernate.connection.url">jdbc:oracle:thin:#localhost:1521:XE
</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.connection.username">system</property>
<property name="hibernate.connection.password">system</property>
<!-- autocommit -->
<property name="hibernate.connection.autocommit">false</property>
<!-- to display sql query generated while running program -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>
<!-- for jdbc transaction -->
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.
JDBCTransactionFactory</property>
<!-- mapping file -->
<mapping resource="Mapping.hbm.xml"/>
</session-factory>
The end tag for <hibernate-configuration> is missing:
</hibernate-configuration>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver </property>
Your opening tag not match the ending tag.

Categories

Resources