0

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 (The .hbm files).

Persistence is one way of doing it, If so can someone tell me how to do it ?

2 Answers 2

1

Every ORM mapping has three parts:

  1. Object(s)
  2. Relational table(s)
  3. 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.

Sign up to request clarification or add additional context in comments.

1 Comment

Annotations ARE a form of mapping.
0

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
}

2 Comments

So will this, create the Tables, and the corresponding attributes and the hibernate mapping ? So when i call saveToAddress (Address address) , and pass and object of Address here, is it suppose to be saved in the DB, without i having to write hibernate mapping files ?
To create the tables, you'd use hbm2ddl: docs.jboss.org/hibernate/core/3.5/reference/en/html/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.