Generate JDO objects from existing database

允我心安 提交于 2019-12-12 09:04:01

问题


Is there a tool to generate JDO objects from an existing database? I prefer a awesome looking Eclipse plugin which i could use to generate and maintain the object but it seems that this is currently not existing. Are other, simple tools to generate the database objects?


回答1:


JDO objects are not simple wrappers around database rows (although you can implement your JDO objects as simple wrappers around database rows if that is what you wish). As such, most automated tools will not know how the object is to be presented by only looking at the database.

For example, an object like:

public class Person {

   private List<PhoneNumber> phoneNumbers;

   ...

   public List<PhoneNumber> getPhoneNumbers() {
     ...
   }

}

might have JDO pre-fetching all the phone numbers for direct inclusion into the object. In the relational database this would probably be done by joining the PhoneNumber database table with the Person database table when constructing the Person object.

Other implementations might look like

public class PhoneNumber {

   public Person getPerson() {
     ...
   }
}

And force the user to fetch a person's phone numbers in a separate database request. It's just not possible for a general purpose tool to predict which manner you wish to use. With two choices (as presented here) it's pretty easy to say "make it configurable!" However, after you add eight or more independent choices in combination, it is not clear that it would be easier to configure the class generation (as opposed to writing the class outright).

Not to mention that JDO wasn't designed for class generation in mind, in fact it was designed to make your hand written classes persistent without generation because the class generation technologies of the day left a lot of visible cruft (undesirable naming patterns, exposed conflicting interfaces and methods, etc).



来源:https://stackoverflow.com/questions/7270943/generate-jdo-objects-from-existing-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!