Hibernate Self Join Many to Many Mapping using self set of id'sHibernate recursive many-to-many association with the same entityHibernate many-to-many mapping and cascade=deleteCreate the perfect JPA entityHibernate: mapping many-to-one association to different parent table depending on type?Mapping a set in Hibernate with a composite primary keyOneToOne mapping on Non Primary-Key Join columnAssociation Hibernate mappingOne to Many and Many to One xml mapping in hibernate With Join tablesHibernate - One to Many Mapping of Set - AnnotationsHow to map many-to-many relation in Hibernate with a extra columns

Why do things cool down?

Is there any actual security benefit to restricting foreign IPs?

What is the word for a person who destroys monuments?

Can I separate garlic into cloves for storage?

Microservices and Stored Procedures

What are the end bytes of *.docx file format

What to do as a player when ranger animal companion dies

Is it safe to unplug a blinking USB drive after 'safely' ejecting it?

Removing rows containing NA in every column

Tips for remembering the order of parameters for ln?

Does battery condition have anything to do with macbook pro performance?

How does one calculate the distribution of the Matt Colville way of rolling stats?

Why do we need to use transistors when building an OR gate?

How do rulers get rich from war?

Is there a connection between IT and Ghostbusters?

What was the deeper meaning of Hermione wanting the cloak?

Inquiry answerer

All numbers in a 5x5 Minesweeper grid

How to count the number of function evaluations in NIntegrate

Can one guy with a duplicator initiate a nuclear apocalypse?

How was ownership of property managed during the Black Death, when so many original owners had died?

I reverse the source code, you negate the output!

Why is the stock market so unpredictable?

How is underwater propagation of sound possible?



Hibernate Self Join Many to Many Mapping using self set of id's


Hibernate recursive many-to-many association with the same entityHibernate many-to-many mapping and cascade=deleteCreate the perfect JPA entityHibernate: mapping many-to-one association to different parent table depending on type?Mapping a set in Hibernate with a composite primary keyOneToOne mapping on Non Primary-Key Join columnAssociation Hibernate mappingOne to Many and Many to One xml mapping in hibernate With Join tablesHibernate - One to Many Mapping of Set - AnnotationsHow to map many-to-many relation in Hibernate with a extra columns






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm trying to create a new hibernate self many-to-many mapping using a set of Long Id's (self id's) what is the correct mapping for it?



I trying to create a mapping between Person and his friends(Persons off course)
I have a Person class map to a tbl_person table.



Person.java



public class Person 
private Long personId;
private String name;
//much more properties in here make this object huge
private Set<Person> friends= new HashSet<Person>();




hibernate Person.hbm.xml mapping:



<set name="friends" table="friends" cascade="none" lazy="false">
<key column="friend_id"/>
<many-to-many column="person_id" class="com.kruders.model.bean.Person"/>
</set>



consider Person class extremely big.
Instead of doing:



 Set<Person> friends


I want to use a set of Person Ids:



 Set<Long> friendsIds


this way I won't be able to hold the entire Person object(again, very big) in memory.



hibernate xml mapping:



Expected results is a mapping table personId (foreign key to tbl_person) to friend (foreign key to tbl_person)
The id of that table is a composite of both columns.



tbl_friends



personId|friend
1 |2
1 |3
2 |1


Thank you.










share|improve this question


























  • why don't you use lazy true?

    – Syed Mehtab Hassan
    Mar 28 at 16:51











  • Thank you for your answer. I will use lazy='true' but do you know how the correct mapping should be look like?

    – Maor Shetrit
    Mar 31 at 7:40











  • There is no way in my knowledge that keep only ids through mapping physically only id is stored but it referes to whole object

    – Syed Mehtab Hassan
    Mar 31 at 7:49

















1















I'm trying to create a new hibernate self many-to-many mapping using a set of Long Id's (self id's) what is the correct mapping for it?



I trying to create a mapping between Person and his friends(Persons off course)
I have a Person class map to a tbl_person table.



Person.java



public class Person 
private Long personId;
private String name;
//much more properties in here make this object huge
private Set<Person> friends= new HashSet<Person>();




hibernate Person.hbm.xml mapping:



<set name="friends" table="friends" cascade="none" lazy="false">
<key column="friend_id"/>
<many-to-many column="person_id" class="com.kruders.model.bean.Person"/>
</set>



consider Person class extremely big.
Instead of doing:



 Set<Person> friends


I want to use a set of Person Ids:



 Set<Long> friendsIds


this way I won't be able to hold the entire Person object(again, very big) in memory.



hibernate xml mapping:



Expected results is a mapping table personId (foreign key to tbl_person) to friend (foreign key to tbl_person)
The id of that table is a composite of both columns.



tbl_friends



personId|friend
1 |2
1 |3
2 |1


Thank you.










share|improve this question


























  • why don't you use lazy true?

    – Syed Mehtab Hassan
    Mar 28 at 16:51











  • Thank you for your answer. I will use lazy='true' but do you know how the correct mapping should be look like?

    – Maor Shetrit
    Mar 31 at 7:40











  • There is no way in my knowledge that keep only ids through mapping physically only id is stored but it referes to whole object

    – Syed Mehtab Hassan
    Mar 31 at 7:49













1












1








1








I'm trying to create a new hibernate self many-to-many mapping using a set of Long Id's (self id's) what is the correct mapping for it?



I trying to create a mapping between Person and his friends(Persons off course)
I have a Person class map to a tbl_person table.



Person.java



public class Person 
private Long personId;
private String name;
//much more properties in here make this object huge
private Set<Person> friends= new HashSet<Person>();




hibernate Person.hbm.xml mapping:



<set name="friends" table="friends" cascade="none" lazy="false">
<key column="friend_id"/>
<many-to-many column="person_id" class="com.kruders.model.bean.Person"/>
</set>



consider Person class extremely big.
Instead of doing:



 Set<Person> friends


I want to use a set of Person Ids:



 Set<Long> friendsIds


this way I won't be able to hold the entire Person object(again, very big) in memory.



hibernate xml mapping:



Expected results is a mapping table personId (foreign key to tbl_person) to friend (foreign key to tbl_person)
The id of that table is a composite of both columns.



tbl_friends



personId|friend
1 |2
1 |3
2 |1


Thank you.










share|improve this question
















I'm trying to create a new hibernate self many-to-many mapping using a set of Long Id's (self id's) what is the correct mapping for it?



I trying to create a mapping between Person and his friends(Persons off course)
I have a Person class map to a tbl_person table.



Person.java



public class Person 
private Long personId;
private String name;
//much more properties in here make this object huge
private Set<Person> friends= new HashSet<Person>();




hibernate Person.hbm.xml mapping:



<set name="friends" table="friends" cascade="none" lazy="false">
<key column="friend_id"/>
<many-to-many column="person_id" class="com.kruders.model.bean.Person"/>
</set>



consider Person class extremely big.
Instead of doing:



 Set<Person> friends


I want to use a set of Person Ids:



 Set<Long> friendsIds


this way I won't be able to hold the entire Person object(again, very big) in memory.



hibernate xml mapping:



Expected results is a mapping table personId (foreign key to tbl_person) to friend (foreign key to tbl_person)
The id of that table is a composite of both columns.



tbl_friends



personId|friend
1 |2
1 |3
2 |1


Thank you.







java hibernate hibernate-mapping






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 14:35









roeygol

4,7985 gold badges31 silver badges62 bronze badges




4,7985 gold badges31 silver badges62 bronze badges










asked Mar 28 at 14:10









Maor ShetritMaor Shetrit

551 silver badge6 bronze badges




551 silver badge6 bronze badges















  • why don't you use lazy true?

    – Syed Mehtab Hassan
    Mar 28 at 16:51











  • Thank you for your answer. I will use lazy='true' but do you know how the correct mapping should be look like?

    – Maor Shetrit
    Mar 31 at 7:40











  • There is no way in my knowledge that keep only ids through mapping physically only id is stored but it referes to whole object

    – Syed Mehtab Hassan
    Mar 31 at 7:49

















  • why don't you use lazy true?

    – Syed Mehtab Hassan
    Mar 28 at 16:51











  • Thank you for your answer. I will use lazy='true' but do you know how the correct mapping should be look like?

    – Maor Shetrit
    Mar 31 at 7:40











  • There is no way in my knowledge that keep only ids through mapping physically only id is stored but it referes to whole object

    – Syed Mehtab Hassan
    Mar 31 at 7:49
















why don't you use lazy true?

– Syed Mehtab Hassan
Mar 28 at 16:51





why don't you use lazy true?

– Syed Mehtab Hassan
Mar 28 at 16:51













Thank you for your answer. I will use lazy='true' but do you know how the correct mapping should be look like?

– Maor Shetrit
Mar 31 at 7:40





Thank you for your answer. I will use lazy='true' but do you know how the correct mapping should be look like?

– Maor Shetrit
Mar 31 at 7:40













There is no way in my knowledge that keep only ids through mapping physically only id is stored but it referes to whole object

– Syed Mehtab Hassan
Mar 31 at 7:49





There is no way in my knowledge that keep only ids through mapping physically only id is stored but it referes to whole object

– Syed Mehtab Hassan
Mar 31 at 7:49












0






active

oldest

votes










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/4.0/"u003ecc by-sa 4.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%2f55399672%2fhibernate-self-join-many-to-many-mapping-using-self-set-of-ids%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.




















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%2f55399672%2fhibernate-self-join-many-to-many-mapping-using-self-set-of-ids%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

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

해남서초등학교 학교 연혁 학교 동문 외부 링크 둘러보기 메뉴북위 34° 34′ 21″ 동경 126° 35′ 50″ / 북위 34.5726385° 동경 126.5972670°  / 34.5726385; 126.5972670해남서초등학교eh