aspose file tools*
The moose likes Object Relational Mapping and the fly likes SQLGrammarException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "SQLGrammarException" Watch "SQLGrammarException" New topic
Author

SQLGrammarException

Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
here is my config file


here is my main class


here is student class


here is address class

here is exception

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Grammar is usually a problem with the mapping.

Can you get an example to work that doesn't use an association? Maybe you should start with something a bit easier.

-Cameron McKenzie
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
I was able to run one to one example.
Also i was able to run many to one mapping without annotation.
This is with many to one mapping with annotation.
I need to study annotation also.
when i am running this example without annotation it works.
can you please tell me where is the error?

here is the site where is Refer

without annotation(Works withour error)
http://www.vaannila.com/hibernate/hibernate-example/hibernate-mapping-many-to-one-1.html

with annotation(still error)
http://www.vaannila.com/hibernate/hibernate-example/hibernate-mapping-many-to-one-using-annotations-1.html
ishan dave
Ranch Hand

Joined: Apr 16, 2007
Posts: 39
hi,

@ManyToOne(cascade = CascadeType.ALL)
public Address getStudentAddress() {
return this.studentAddress;
}

please put the join column name like

@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name="ADDRESS_ID")
public Address getStudentAddress() {
return this.studentAddress;
}

thank you,
ishaan
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
i change my student clas

still i get this error?



i think this may be database error?
if there is @GeneratedValue in id filed is it must to make default value for clume value?
ishan dave
Ranch Hand

Joined: Apr 16, 2007
Posts: 39
hi,
may know your DDL of both the tables.

Do you have Address_id column in your Student tale ?
if not then please put that.

and please make sure that you checked the auto-increment on in both your tables in mysql.


thank you,
ishaan
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
I manually created the tables.
here is a site witch i use.
http://www.vaannila.com/hibernate/hibernate-example/hibernate-mapping-many-to-one-using-annotations-1.html

there is a address columne in student table.
can you send me the DDL please?
i didn't use DDl .i make tables manually.
how to check auto-increment option?
Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 189
You talk to your MySQL in a language only you and MySQL understand?!? Quite cool... If you don't know what he means with "DDL", you could ask. He wants you to show us, how your table looks like. That means table name, column names and column types. Maybe you don't a column named ADRESS_ID, because thats what the error is about.
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
here is screen shot of my student table
http://3.bp.blogspot.com/_bpkZ2BsqXug/S2byNyT3tWI/AAAAAAAAABw/rv4cL0dy34U/s1600-h/student.GIF

here is a screenshot of my address table
http://4.bp.blogspot.com/_bpkZ2BsqXug/S2byf5z8VdI/AAAAAAAAAB4/MUs24v3Ixtw/s1600-h/address.GIF
ishan dave
Ranch Hand

Joined: Apr 16, 2007
Posts: 39
i am not able to see the images of your tables
Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 189
If you switch to the mobile version of the forum you see the complete link.
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
student
http://1.bp.blogspot.com/_bpkZ2BsqXug/S2mTSN0RnNI/AAAAAAAAADc/ZU1DuBhMNsc/s1600-h/student.GIF


address
http://1.bp.blogspot.com/_bpkZ2BsqXug/S2mTYxG6vgI/AAAAAAAAADk/XfJOIKm_Fh4/s1600-h/address.GIF

anyway when creating table is it should add address?_id as a forieng key ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQLGrammarException