Bind datasource to persistence on Intellij fails on resolve column - java

I'm starting learing how to use IntelliJ, and I'm trying to link my persistence to my datasource.
I've read here on SO how to do that, and now I've binded my persistence to my datasource successfully: I can run queries on database, and i can browse my persistence.
This is the db (MSSQL):
This is the persistence:
And this is the assignment:
The problem is that I'm still getting error on my class, looks like is not able to link to the datasource, and is giving me the error "Cannot resolve column" (not only on ID column, but on all columns):
The application is running fine, so the problem is only related to some wrong intellij configuration, but I can't find where the problem is.
This is my hibernate.cfg.xml (there are more tables, I've left only the one in the example):
<?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 name="Artemide">
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<!-- Configurazione maven-->
<property name="hibernate.connection.password">${hibernate.password}</property>
<property name="hibernate.connection.username">${hibernate.username}</property>
<property name="hibernate.connection.url">${hibernate.connection.url}</property>
<property name="hibernate.default_catalog">${hibernate.default_catalog}</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</property>
<property name="hibernate.search.autoregister_listeners">false</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.format_sql">true</property>
<mapping class="xx.xx.xx.database.pojo.Categoria"/>
</session-factory>
</hibernate-configuration>
Thanks!

Related

java.lang.UnsupportedOperationException : The application must supply JDBC connections

<?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>
<property name ="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name ="conection.url">jdbc:mysql://localhost:3306/employeesdb</property>
<property name ="connection.username">root</property>
<property name ="connection.password">password#123</property>
<property name ="hbm2ddl.auto">update</property>
<property name ="show_sql">true</property>
<property name="current_session_context_class">thread</property>
<mapping class = "com.start.Student"></mapping>
</session-factory>
</hibernate-configuration>
Normally I should be able to connect to DB but I am getting an error.
Error: - "Exception in thread "main" java.lang.UnsupportedOperationException: The application must supply JDBC connections"
It means I am not able to connect with DB.
I have checked that the database username and password are correct.
ERROR
Main Program
You have typo in conection.url. Should be connection.url.

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.

Hibernate.cfg.xml not found after deploy the web app to heroku

After deploying a web application with maven to heroku cloud, I get log error:
app[web.1]: org.hibernate.HibernateException: hibernate.cfg.xml not found.
The web application running locally correctly, but on the cloud not.
This is my hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//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:3306/todoitemsdb
</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping class="il.ac.hit.model.User" resource="todoitems.xml"/>
<mapping class="il.ac.hit.model.ToDoItem" resource="users.xml"/>
</session-factory>
</hibernate-configuration>
What can I do?
Make sure that the hibernate.cfg.xml is bundled into your jar like this:
your-app.jar\hibernate.cfg.xml
That's where Hibernate tries to locate the configuration file.
I had my hibernate.cfg.xml under resources under a folder config
Changing the below line
cfg.configure("./config/hibernate.cfg.xml");
to
cfg.configure("config/hibernate.cfg.xml");
worked.

org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml

please help me in resolving this error.
org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1494)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
at org.jbpm.db.hibernate.HibernateHelper.createConfiguration (HibernateHelper.java:89)
at org.jbpm.persistence.db.DbPersistenceServiceFactory.getConfiguration (DbPersistenceServiceFactory.java:75)
at org.jbpm.persistence.db.DbPersistenceServiceFactory.getSessionFactory(DbPersistenceServiceFactory.java:104)
at org.jbpm.persistence.db.DbPersistenceService.getSessionFactory(DbPersistenceService.java:93)
at org.jbpm.persistence.jta.JtaDbPersistenceService.getTransactionManager(JtaDbPersistenceService.java:100)
at org.jbpm.persistence.jta.JtaDbPersistenceService.getTransactionStatus(JtaDbPersistenceService.java:88)
at org.jbpm.persistence.jta.JtaDbPersistenceService.<init>(JtaDbPersistenceService.java:50)
at org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory.openService(JtaDbPersistenceServiceFactory.java:61)
at org.jbpm.svc.Services.getService(Services.java:160)
at org.jbpm.svc.Services.getPersistenceService(Services.java:197)
at org.jbpm.JbpmContext.getPersistenceService(JbpmContext.java:695)
at org.jbpm.JbpmContext.getJobSession(JbpmContext.java:639)
at org.jbpm.job.executor.LockMonitorThread.unlockOverdueJobs(LockMonitorThread.java:64)
at org.jbpm.job.executor.LockMonitorThread.run(LockMonitorThread.java:43)
Caused by: org.dom4j.DocumentException: Connection reset Nested exception: Connection reset
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1484)
... 15 more
I am new to hibernate and having difficulty in understanding what the error is. The jar files used for hibernate are as
hibernate-annotations.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate3.jar
my hibernate.cfg.xml file is as
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/datacenter</property>
<property name="connection.username">root</property>
<property name="connection.password">admin</property>
<!-- <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
-->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="show_MySql">TRUE</property>
<property name="format_sql">TRUE</property>
<!-- <property name="jboss.as.jpa.providerModule">hibernate3- bundled</property> -->
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<!-- <property name="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTransla torFactory</property> -->
<!-- List of annotated classes-->
<!-- Associations -->
<!-- One to one -->
<!-- <mapping class="Emp_Timecard" />
<mapping class="maindoor" /> -->
<mapping class="model.serverroom" />
<mapping class="model.resourcelist" />
<mapping class="model.timesheet" />
<mapping class="model.maindoor" />
<!-- <mapping class="timesheet" />
<mapping class="Resource_list"/> -->
</session-factory>
</hibernate-configuration>
I think you are having an issue with connecting to the db properly. Are you sure the user name and password are correct? Or did you have an already a database called datacenter?
Also try changing the doctype as
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
See Can't parse hibernate.cfg.xml while offline
Depending on your hibernate version it might be that hibernate is trying to load the DTD from the internet and that the connection is reset in the meantime.
to run hibernate application offline use 'hibernate-core jar' file it will work..
no need to change your Hibernate configuration file .Avvappa,BEL.
change ur hiber configuration i.e
<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 as below -------------------------------------
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.5//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
change your Hibernate configuration as follows;
<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 as below -------------------------------------
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.5//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
Try Running the program while your system is connected to Internet
I was facing the same issue. And when i searched for the solution online found this thread regarding the same issue.
I went back and tried running the program again and it worked, the only changes made were connected to Internet Connection. I turned off the connection and again the program was giving the same error as you got.
My guess is the Hibernate configuration file is downloading the DTD from internet, and when it fails to do so it gives error while creating the SessionFactory object.
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
If the configuration file is not parsed, just check for the hibernate version. If it is hibernate 3 the DTD should be from Sourceforge website. if it is the later version the DTD should be
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

Categories

Resources