Is there a way to map an Entity class (Address.java) to MySQL without using Hibernate Mapping (.hbm files)
What i need to do is to Create a table called 'Address' in the MySQL DB, and create Columns with the attributes of this class, and later populate them.
But i need to do it without writing Hibernate mapping files (开发者_C百科The .hbm
files).
Persistence is one way of doing it, If so can someone tell me how to do it ?
Every ORM mapping has three parts:
- Object(s)
- Relational table(s)
- Mapping(s)
You have to have two to generate the third. If you have an object and its mapping, you can generate the table. If you have the table and the mapping, you can generate the object.
The only way you can generate without having to establish mappings is to use a framework like Grails that favors convention over configuration. That means they make assumptions about the mapping on your behalf.
But the ORM tool can't read your mind.
Use annotations instead of XML: http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#entity-overview
In your case, you would start by annotating the Address
class with @Entity
:
@Entity
@Table(name = "Address")
public class Address implements Serializable
{
// fields
// ctors
// getters & setters
}
精彩评论