1

Our Hibernate configuration mapping have been implemented programatically in java, not with annotation and not with XML mapping.

We have a mapping classes hierarchy that we're setting in the Hibernate Mappings instance when the context is initialized, for instance:

Mappings mappings = configuration.createMappings();
mappings.addClass(PersistentClass instance);

Now, the issue I'm facing with is quite simple but i don't find an example how to add it for our implementation.

Let's say that

we have 2 tablesA and B with Many to one relation, A.type_id = B.id. and i want to retrieve all records from A with the following condition: A.type_id = B.id and B.id = 4;

How can i add the association (many to one) in my mapping object. org.hibernate.mapping.RootClass.

1
  • what is asked in question Header and what is described in body are different. Correct Commented Nov 7, 2012 at 7:53

2 Answers 2

3

The question is old, but maybe the answer help someone other.

The topic is to complex to be answered here. Unfortunately the Hibernate documentation does not contain a lot of information and even the source code itself is not documentated at all.

This blog post http://portofino.manydesigns.com/en/blog/configuring-hibernate-programmatically (and the second part of it) gives an overview of how to create the mapping programmatically.

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

Comments

0

Check out the answer of here

Also note that .addclass does not work as easily as you think it should. You need a cfg.xml and hbm file combination.

1 Comment

Use Configuration#addAnnotatedClass() to get rid of the xml files.

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.