-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Unit Testing Hibernate Mappings?
PostPosted: Mon Apr 16, 2007 3:17 pm 
Beginner
Beginner

Joined: Tue Jun 07, 2005 8:24 am
Posts: 33
Location: Cincinnati, OH
I would like to be create (or hopefully find) a nice framework for unit testing my mapping documents. Basically, I want to be able to say something like "assert that the 'name' property in the 'Person' class is mapped to the 'NAME' column in the 'PERSON' table." I would like to use the hibernate metadata to find out where the properties are to be persisted so that I can do this sort of check. Any tips? Thanks

James

Hibernate version: 3.2.2.ga


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 9:06 am 
Newbie

Joined: Fri Mar 30, 2007 7:15 pm
Posts: 6
Take a look at the book "POJOs in Action" by Chris Richardson. He provides a JUnit extension called ormunit which lets you test your mappings and even validate them against the database schema.


Top
 Profile  
 
 Post subject: Re: Unit Testing Hibernate Mappings?
PostPosted: Wed Apr 18, 2007 9:14 am 
Beginner
Beginner

Joined: Tue Jun 07, 2005 8:24 am
Posts: 33
Location: Cincinnati, OH
sgabal,

Thanks for the reply. I actually got the idea for the code I need from PIA (great book). I didn't see how to specifically check which column the property was mapped to, though.

We did find a way to do it. We got the configuration object we used to construct the SessionFactory and we asked for the PersistentClass we wanted. From there, you can ask for the specific Property object you're interested in. It has an iterator of the columns to which it is mapped. That's what we're going to use, I think.

James


Top
 Profile  
 
 Post subject: Unit testing Hibernate mappings
PostPosted: Fri Apr 27, 2007 4:50 pm 
Newbie

Joined: Tue Mar 15, 2005 1:07 am
Posts: 5
I'm glad that you liked my book.

BTW You could have used assertField() to test whether a field was mapped. However, the version in the book didn't support mapping properties - not a fan of that so I never implemented.

Coincidentally, I am just in the middle of turning ORMUnit into an open-source project: cleaning up the code, implementing support for property mapping, writing some docs etc. I hope to be done in the next few days and will post an announcement to my blog.

Chris

Author, POJOs in Action - http://www.manning.com/crichardson
Enterprise POJO consulting and training - http://www.chrisrichardson.net
Enterprise POJOs blog - http://chris-richardson.blog-city.com
Speaking in 2007 at JavaOne, SpringOne, and the Colorado Software Summit


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.