Auto populate POJO.. Is there a library that can do this?

M

muthu.ramadoss

Folks,

Anyone know of any libraries that can autopopulate a pojo?

Ex:

I have a User object with first name and last name as members. I would
want to auto populate the object with some random values so the user
object can be used right away.

User user = new User ();

// Explicit member assignment
user.setFirstName ("John");
user.setLastName ("Doe");

// I need this

AutoPopulateLibrary.fill (user);

OR

user = AutoPopulateLibrary.fill (User.class);

I'll pass the user object or the class name or whatever and the target
object must be magically filled.

Can this be done already, or Am i missing something here?

Please comment.
 
H

Harry Bosch

C

Chris Smith

User user = new User ();

// Explicit member assignment
user.setFirstName ("John");
user.setLastName ("Doe");

// I need this

AutoPopulateLibrary.fill (user);

And where do you expect to get the data ("John" and "Doe") from?

The term "POJO" is often used with O/R mapping; is the data in a
relational database? If so, you'll have to pass in some kind of key or
other information to identify the object you want; otherwise the data
can't be found. Products to do this kind of work include Hibernate,
EJB-CMP, Oracle TopLink, several JDO vendors, and dozens more. Off-hand
and without knowing your specific needs, I'd start by looking into
Hibernate.

If the data is elsewhere besides a database, please let us know where
it's supposed to come from. Otherwise, you really DO want magic, and
computer programs don't excel at ESP.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
M

muthu.ramadoss

Yes I have looked into the Jakarta commons BeanUtil class. As you
rightly said it would require properties to be manually fed.

What I need is the pojo to be auto filled. This can be used for OR map
testing with hibernate etc.,

The entire use case i am describing fits more on the testing side than
on the development scenario.

In short the test use case would be:

Instantiate objects and fill data automatically.
save in database (so OR mapping can be tested)
remove them.
 
M

muthu.ramadoss

No I really dont care about the data.. The data can be anything.. thats
why it can be auto filled.

As I replied above, this is more of an test use case which would test
the hibernate OR mapping.

This seems to be a nice little utility to write and I think would also
benefit the community as well.

What do you think? Is this my chance to write this utility and shoot
into the Java limelight :)
 
R

Roedy Green

No I really dont care about the data.. The data can be anything.. thats
why it can be auto filled.

If you don't have it as a bean, then you have to use reflection. Find
the fields, and depending on field type use the corresponding number
generator. For references you are hosed.
 
M

muthu.ramadoss

For references, can we not recursively walk through the reference and
autofill?

Do any of you feel this would be a nice little utility that can come in
handy for filling up 100's of objects for a variety of test cases?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top