Consultation Entity without its Associations

Asked

Viewed 33 times

0

I’m creating an app with JAVA SE + HIBERNATE. I am having a "problem" in making a query to a single Entity. Then, it would be possible to make a query in the entity(TABELA) without the relational mapping @One-to-One,@One-to-Many, @Many-to-One, @Many-to-Many ?

Thanks in advance for understanding

1 answer

3


Yes, it is possible.

Relationships only exist to facilitate the retrieval of information related to an entity. Without them it would be necessary to design the queries explaining joins and therefore losing in a certain way the power that Hibernate provides.

If the reason for not using mapping is because the queries bring a lot of information or take time, you can always use the FetchType.LAZY in the mappings you have.
Using this way, it is as if there is no mapping because the relationship data will only be loaded if you explicitly use it (calling a get pro object or an iterator for Collection).

It is important to note that without the mapping no entity that does not represent a supported type in the database can be assigned to an attribute without proper mapping.
This restriction exists because Hibernate has no way of knowing which table the entity represents without being made explicit to it through annotations or xml file configuration (Hibernate.cfg.xml).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.