Hibernate oneToMany without mapping or joining












0















Is it possible to add a list of Entitys into another Entity without having a mapping or joinColumn?



What I want is something like



EntityA{
@OneToMany
List<EntityX> allEntitiesX
}


This List should behave like



Query query=session.createQuery("from EntityX"); 
List allEntitiesX=query.list();


So if I load the EntiyA I also have acces to all other entities EntityX(with lazy-loading) without "leaving" EntityA. Due to our legacy programm I can not add a new table to connect both Entitys, because I would have to update all existing customer data and teach the old system to handle this joinTable the same way.



If possible beeing able to filter with conditions would be good aswell.



Why I want it:
In our system every "mainEntity" can have properties (EntityX).
Every property entity has a list of values, and these values are mapped with a joinTable to the "mainEntity".
If I want to add a method setProperty(propertyName, value) I have the problem that I cant find the correct propertyEntity to add my value.
The setter would have to be moved to a place where I can do entityManager querys.










share|improve this question

























  • It is completely unclear what you are asking.

    – Alan Hay
    Nov 20 '18 at 9:38
















0















Is it possible to add a list of Entitys into another Entity without having a mapping or joinColumn?



What I want is something like



EntityA{
@OneToMany
List<EntityX> allEntitiesX
}


This List should behave like



Query query=session.createQuery("from EntityX"); 
List allEntitiesX=query.list();


So if I load the EntiyA I also have acces to all other entities EntityX(with lazy-loading) without "leaving" EntityA. Due to our legacy programm I can not add a new table to connect both Entitys, because I would have to update all existing customer data and teach the old system to handle this joinTable the same way.



If possible beeing able to filter with conditions would be good aswell.



Why I want it:
In our system every "mainEntity" can have properties (EntityX).
Every property entity has a list of values, and these values are mapped with a joinTable to the "mainEntity".
If I want to add a method setProperty(propertyName, value) I have the problem that I cant find the correct propertyEntity to add my value.
The setter would have to be moved to a place where I can do entityManager querys.










share|improve this question

























  • It is completely unclear what you are asking.

    – Alan Hay
    Nov 20 '18 at 9:38














0












0








0








Is it possible to add a list of Entitys into another Entity without having a mapping or joinColumn?



What I want is something like



EntityA{
@OneToMany
List<EntityX> allEntitiesX
}


This List should behave like



Query query=session.createQuery("from EntityX"); 
List allEntitiesX=query.list();


So if I load the EntiyA I also have acces to all other entities EntityX(with lazy-loading) without "leaving" EntityA. Due to our legacy programm I can not add a new table to connect both Entitys, because I would have to update all existing customer data and teach the old system to handle this joinTable the same way.



If possible beeing able to filter with conditions would be good aswell.



Why I want it:
In our system every "mainEntity" can have properties (EntityX).
Every property entity has a list of values, and these values are mapped with a joinTable to the "mainEntity".
If I want to add a method setProperty(propertyName, value) I have the problem that I cant find the correct propertyEntity to add my value.
The setter would have to be moved to a place where I can do entityManager querys.










share|improve this question
















Is it possible to add a list of Entitys into another Entity without having a mapping or joinColumn?



What I want is something like



EntityA{
@OneToMany
List<EntityX> allEntitiesX
}


This List should behave like



Query query=session.createQuery("from EntityX"); 
List allEntitiesX=query.list();


So if I load the EntiyA I also have acces to all other entities EntityX(with lazy-loading) without "leaving" EntityA. Due to our legacy programm I can not add a new table to connect both Entitys, because I would have to update all existing customer data and teach the old system to handle this joinTable the same way.



If possible beeing able to filter with conditions would be good aswell.



Why I want it:
In our system every "mainEntity" can have properties (EntityX).
Every property entity has a list of values, and these values are mapped with a joinTable to the "mainEntity".
If I want to add a method setProperty(propertyName, value) I have the problem that I cant find the correct propertyEntity to add my value.
The setter would have to be moved to a place where I can do entityManager querys.







hibernate jpa






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 15:34







OME

















asked Nov 20 '18 at 8:50









OMEOME

11




11













  • It is completely unclear what you are asking.

    – Alan Hay
    Nov 20 '18 at 9:38



















  • It is completely unclear what you are asking.

    – Alan Hay
    Nov 20 '18 at 9:38

















It is completely unclear what you are asking.

– Alan Hay
Nov 20 '18 at 9:38





It is completely unclear what you are asking.

– Alan Hay
Nov 20 '18 at 9:38












1 Answer
1






active

oldest

votes


















0














Yes that is possible but that will create another third table but you actually dont need third table in case of onetomany and manytoone as every row of EntityX will contain one column for EntityA.



The simplest mapping you can do is like below.



EntityA{
@OneToMany(mappedBy="entityA",cascade = CascadeType.ALL,fetch = FetchType.LAZY)
List<EntityX> allEntitiesX
}


And in another entity



EntityX{
@ManyToOne
EntityA entityA;
}





share|improve this answer
























  • Thank you for the quick answer, but I fear this will not help me because I reality it would be a manyToMany connection (but I need only one direction). Additionaly I cant change the tables because antothes non-JPA system is working on the same database. If the answer in this case is no I will mark this answer as Accepted

    – OME
    Nov 20 '18 at 9:27













  • refer this websystique.com/hibernate/…

    – Alien
    Nov 20 '18 at 9:30











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389263%2fhibernate-onetomany-without-mapping-or-joining%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Yes that is possible but that will create another third table but you actually dont need third table in case of onetomany and manytoone as every row of EntityX will contain one column for EntityA.



The simplest mapping you can do is like below.



EntityA{
@OneToMany(mappedBy="entityA",cascade = CascadeType.ALL,fetch = FetchType.LAZY)
List<EntityX> allEntitiesX
}


And in another entity



EntityX{
@ManyToOne
EntityA entityA;
}





share|improve this answer
























  • Thank you for the quick answer, but I fear this will not help me because I reality it would be a manyToMany connection (but I need only one direction). Additionaly I cant change the tables because antothes non-JPA system is working on the same database. If the answer in this case is no I will mark this answer as Accepted

    – OME
    Nov 20 '18 at 9:27













  • refer this websystique.com/hibernate/…

    – Alien
    Nov 20 '18 at 9:30
















0














Yes that is possible but that will create another third table but you actually dont need third table in case of onetomany and manytoone as every row of EntityX will contain one column for EntityA.



The simplest mapping you can do is like below.



EntityA{
@OneToMany(mappedBy="entityA",cascade = CascadeType.ALL,fetch = FetchType.LAZY)
List<EntityX> allEntitiesX
}


And in another entity



EntityX{
@ManyToOne
EntityA entityA;
}





share|improve this answer
























  • Thank you for the quick answer, but I fear this will not help me because I reality it would be a manyToMany connection (but I need only one direction). Additionaly I cant change the tables because antothes non-JPA system is working on the same database. If the answer in this case is no I will mark this answer as Accepted

    – OME
    Nov 20 '18 at 9:27













  • refer this websystique.com/hibernate/…

    – Alien
    Nov 20 '18 at 9:30














0












0








0







Yes that is possible but that will create another third table but you actually dont need third table in case of onetomany and manytoone as every row of EntityX will contain one column for EntityA.



The simplest mapping you can do is like below.



EntityA{
@OneToMany(mappedBy="entityA",cascade = CascadeType.ALL,fetch = FetchType.LAZY)
List<EntityX> allEntitiesX
}


And in another entity



EntityX{
@ManyToOne
EntityA entityA;
}





share|improve this answer













Yes that is possible but that will create another third table but you actually dont need third table in case of onetomany and manytoone as every row of EntityX will contain one column for EntityA.



The simplest mapping you can do is like below.



EntityA{
@OneToMany(mappedBy="entityA",cascade = CascadeType.ALL,fetch = FetchType.LAZY)
List<EntityX> allEntitiesX
}


And in another entity



EntityX{
@ManyToOne
EntityA entityA;
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 8:57









AlienAlien

4,85331026




4,85331026













  • Thank you for the quick answer, but I fear this will not help me because I reality it would be a manyToMany connection (but I need only one direction). Additionaly I cant change the tables because antothes non-JPA system is working on the same database. If the answer in this case is no I will mark this answer as Accepted

    – OME
    Nov 20 '18 at 9:27













  • refer this websystique.com/hibernate/…

    – Alien
    Nov 20 '18 at 9:30



















  • Thank you for the quick answer, but I fear this will not help me because I reality it would be a manyToMany connection (but I need only one direction). Additionaly I cant change the tables because antothes non-JPA system is working on the same database. If the answer in this case is no I will mark this answer as Accepted

    – OME
    Nov 20 '18 at 9:27













  • refer this websystique.com/hibernate/…

    – Alien
    Nov 20 '18 at 9:30

















Thank you for the quick answer, but I fear this will not help me because I reality it would be a manyToMany connection (but I need only one direction). Additionaly I cant change the tables because antothes non-JPA system is working on the same database. If the answer in this case is no I will mark this answer as Accepted

– OME
Nov 20 '18 at 9:27







Thank you for the quick answer, but I fear this will not help me because I reality it would be a manyToMany connection (but I need only one direction). Additionaly I cant change the tables because antothes non-JPA system is working on the same database. If the answer in this case is no I will mark this answer as Accepted

– OME
Nov 20 '18 at 9:27















refer this websystique.com/hibernate/…

– Alien
Nov 20 '18 at 9:30





refer this websystique.com/hibernate/…

– Alien
Nov 20 '18 at 9:30


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389263%2fhibernate-onetomany-without-mapping-or-joining%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

'app-layout' is not a known element: how to share Component with different Modules