last day (14 days later) » 

11:51 AM
0
A: Hibernate "hbm2ddl - create" does not work in spring

Niku HysaCan you try to change this from <prop key="hibernate.hbm2ddl.auto">create</prop> to <prop key="hibernate.hbm2ddl.auto">update</prop>

 
Yes. But it didn't make any difference. The error I get is - could not execute query... By the way making it update cannot help, because I want to create the tables automatically
 
Have you tested the configuration if they are correct?
 
The config seems right because it already worked on another project. (with hbm2ddl - update) I only changed the params dbname, domain class list & the layer mapping part.
 
Does your server prints any error? Can you provide them? Your Server error ouput, like Glassfish output!
 
It doesn't print an error. It only prints the hibernate select query and then the browser displays the above mentioned error - Could not execute query. I added the e.printStackTrace(); also but no difference
 
11:51 AM
What browser are you using, there should be a tab called output, where it displays all the log of the server!
Hi
Are you Praveen there?
 
Hi
Im using chrome
 
I meant what ide
Netbeans
Eclipse?
 
ah no, Spring Tool Suite... yes, based on eclipse
 
Does it have an ouput tab? I'm not used to it
 
just now i got this error when i made some modifications to the error handling :-

org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2536)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
yeah it does, I just posted the error it gave
it says no such column found, obviously because the table is not created
 
12:01 PM
Well, because it is not working correctly, it does not create table, or find columns
 
actually it says column this_.userid does not exist
yeah
why doesn't it create the tables?
 
Can you paste your model class?
 
package com.praveen.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class User {
private int userId;
private String fName;
private String lName;
private String username;
private String password;

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
 
You are missing the @Table annotation
@Entity
@Table(name = "User")
public class User{ .....
Try and tell me the result
 
woah, it worked!!
 
12:05 PM
You are wellcome
 
I can't believe it man, earlier in my other project I didn't add that annotation... But I guess for Spring ORM it is a must... Thanks Mate. Please add that solution as a comment to my problem, I'll accept it
Thanks a lot
 
Thanks
yeah, in orm its a must to provide the table annotation
 
Ok Mate, See Ya around!! :-)
 
Thanks
you can message me if you have further problems
You are wellcome
 
12:26 PM
Actually I found something interesting. The @Table annotation is not mandatory, the problem was that in PostgreSQL, there's a system table named user. Since my domain class also contained the same name, it doesn't let me override that table. Now I created another domain class named TestMe without the @Table annotation, only with the @Entity, and it worked!
yeah sure mate, I will.. Thanks :-)
 

last day (14 days later) »