Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

type "Long" and primitive "long"

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two exactly same .hbm files. One is , to define "id" type as "Long" , another one is, to define "id" type as primitive "long".

Then use schemaexport, one with primitive "long" works , another one is failed.

The error message is about "Long"


Why ?
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Edward Chen:
One is , to define "id" type as "Long" , another one is, to define "id" type as primitive "long".


I found the reason, finally. when we set the hbm file, "Long" should be "java.lang.Long", not plain "Long", and "unsaved-value" should be "null". If we use primitive "long", the "unsaved-value" should be "0". (I don't know why "-1" is NOT option).

Here I should talk about some online tutorial. I have download some hibernate tutorial, the author didn't pay attention to this difference. But it works.

But maybe you guys want to use Hibernate Synchronizer to test same application. Say "<id ... type="long" unsaved-value="null" ...>, the Hibernate Synchronzier can generate coding, but can't not generate schema and run test.java.

Anyway, the good programming habit is


The first one is recommended. If we are careful at this difference, we can prevent lots of unexpected runtime error.

If I am wrong, please correct me.

Thanks
 
Sundar Murthi
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chang.,
Is it possible to specify the java class object to DB columns.

because in our project peoples r using BigDecimal as a field in POJO. but i cant able to map with my DB table.

I can able to map it in any way. or how can i change the BigDecimal type to oracle column type

thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic