JPA/Hibernate manyToMany relation mapping with additional fields












0















I have manyToMany relationship mapping and couldn't get it to work. I have read many posts and articles and couldn't figure this one out. If anyone has some idea please share.



I have tried to simplify diagram and code as much.



My database is designed like this:
enter image description here



My entities look like this (at least final attempt before asking):
Client:



@Entity
@Table(name = "client")
public class Client implements Serializable {
@Id
@Column(name = "client_id")
private int id;

... other fields
}


Project:



@Entity
@Table(name = "project")
public class Project implements Serializable {
@EmbeddedId
private ProjectId id;

... other fields

@Embeddable
class ProjectId implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@Column(name = "project_id")
private int projectId;
}
}


User:



@Entity
@Table(name = "user")
public class User implements Serializable {
@EmbeddedId
private UserId id;

... other fields

@Embeddable
class UserId implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@Column(name = "user_id")
private int userId;
}
}


ProjectUser:



@Entity
@Table(name = "project_user")
public class ProjectUser implements Serializable {
@EmbeddedId
private ProjectUserId id;

... other fields

@Embeddable
class ProjectUserId implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "project_id", referencedColumnName = "project_id", insertable = false, updatable = false) })
private Project project;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false) })
private User user;
}
}


Before adding ProjectUser entity everything is working fine.

Now when I'm starting server it says:




Repeated column in mapping for entity: ProjectUser column: client_id
(should be mapped with insert="false" update="false")"}}




So, the question is how do I make this work?



EDIT:
Java application will be mostly REST services providing data. Database design is as is. It has logical sense and most of the business logic will be in database. We have people with very good DB knowledge working on this and it would not make much sense changing database design because of JPA/Hibernate limitations.










share|improve this question

























  • Start with redesigning your schema. This doesn't really make any sense to me. For example, you have projectId for Project so you don't clientId as part of the primary key. Same with User. What is project_user trying to tell you? If it is just supposed to map Users to Projects and Projects to Users fine, but then what's the clientId for? This all looks like you started with a many-to-many and added Client and stuck clientId into everything. Define what you're trying to do at a more abstract level first.

    – K.Nicholas
    Nov 22 '18 at 18:45











  • I have edited the original question for some clarification. Thank you for the suggestion but I would really want to know if this is possible to map using current database schema.

    – hyperion385
    Nov 23 '18 at 10:15











  • "We have people with very good DB knowledge working on this" -- or not. I can visualize doing this with JPA but it still doesn't make sense so it's not worth it.

    – K.Nicholas
    Nov 23 '18 at 15:24


















0















I have manyToMany relationship mapping and couldn't get it to work. I have read many posts and articles and couldn't figure this one out. If anyone has some idea please share.



I have tried to simplify diagram and code as much.



My database is designed like this:
enter image description here



My entities look like this (at least final attempt before asking):
Client:



@Entity
@Table(name = "client")
public class Client implements Serializable {
@Id
@Column(name = "client_id")
private int id;

... other fields
}


Project:



@Entity
@Table(name = "project")
public class Project implements Serializable {
@EmbeddedId
private ProjectId id;

... other fields

@Embeddable
class ProjectId implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@Column(name = "project_id")
private int projectId;
}
}


User:



@Entity
@Table(name = "user")
public class User implements Serializable {
@EmbeddedId
private UserId id;

... other fields

@Embeddable
class UserId implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@Column(name = "user_id")
private int userId;
}
}


ProjectUser:



@Entity
@Table(name = "project_user")
public class ProjectUser implements Serializable {
@EmbeddedId
private ProjectUserId id;

... other fields

@Embeddable
class ProjectUserId implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "project_id", referencedColumnName = "project_id", insertable = false, updatable = false) })
private Project project;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false) })
private User user;
}
}


Before adding ProjectUser entity everything is working fine.

Now when I'm starting server it says:




Repeated column in mapping for entity: ProjectUser column: client_id
(should be mapped with insert="false" update="false")"}}




So, the question is how do I make this work?



EDIT:
Java application will be mostly REST services providing data. Database design is as is. It has logical sense and most of the business logic will be in database. We have people with very good DB knowledge working on this and it would not make much sense changing database design because of JPA/Hibernate limitations.










share|improve this question

























  • Start with redesigning your schema. This doesn't really make any sense to me. For example, you have projectId for Project so you don't clientId as part of the primary key. Same with User. What is project_user trying to tell you? If it is just supposed to map Users to Projects and Projects to Users fine, but then what's the clientId for? This all looks like you started with a many-to-many and added Client and stuck clientId into everything. Define what you're trying to do at a more abstract level first.

    – K.Nicholas
    Nov 22 '18 at 18:45











  • I have edited the original question for some clarification. Thank you for the suggestion but I would really want to know if this is possible to map using current database schema.

    – hyperion385
    Nov 23 '18 at 10:15











  • "We have people with very good DB knowledge working on this" -- or not. I can visualize doing this with JPA but it still doesn't make sense so it's not worth it.

    – K.Nicholas
    Nov 23 '18 at 15:24
















0












0








0








I have manyToMany relationship mapping and couldn't get it to work. I have read many posts and articles and couldn't figure this one out. If anyone has some idea please share.



I have tried to simplify diagram and code as much.



My database is designed like this:
enter image description here



My entities look like this (at least final attempt before asking):
Client:



@Entity
@Table(name = "client")
public class Client implements Serializable {
@Id
@Column(name = "client_id")
private int id;

... other fields
}


Project:



@Entity
@Table(name = "project")
public class Project implements Serializable {
@EmbeddedId
private ProjectId id;

... other fields

@Embeddable
class ProjectId implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@Column(name = "project_id")
private int projectId;
}
}


User:



@Entity
@Table(name = "user")
public class User implements Serializable {
@EmbeddedId
private UserId id;

... other fields

@Embeddable
class UserId implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@Column(name = "user_id")
private int userId;
}
}


ProjectUser:



@Entity
@Table(name = "project_user")
public class ProjectUser implements Serializable {
@EmbeddedId
private ProjectUserId id;

... other fields

@Embeddable
class ProjectUserId implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "project_id", referencedColumnName = "project_id", insertable = false, updatable = false) })
private Project project;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false) })
private User user;
}
}


Before adding ProjectUser entity everything is working fine.

Now when I'm starting server it says:




Repeated column in mapping for entity: ProjectUser column: client_id
(should be mapped with insert="false" update="false")"}}




So, the question is how do I make this work?



EDIT:
Java application will be mostly REST services providing data. Database design is as is. It has logical sense and most of the business logic will be in database. We have people with very good DB knowledge working on this and it would not make much sense changing database design because of JPA/Hibernate limitations.










share|improve this question
















I have manyToMany relationship mapping and couldn't get it to work. I have read many posts and articles and couldn't figure this one out. If anyone has some idea please share.



I have tried to simplify diagram and code as much.



My database is designed like this:
enter image description here



My entities look like this (at least final attempt before asking):
Client:



@Entity
@Table(name = "client")
public class Client implements Serializable {
@Id
@Column(name = "client_id")
private int id;

... other fields
}


Project:



@Entity
@Table(name = "project")
public class Project implements Serializable {
@EmbeddedId
private ProjectId id;

... other fields

@Embeddable
class ProjectId implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@Column(name = "project_id")
private int projectId;
}
}


User:



@Entity
@Table(name = "user")
public class User implements Serializable {
@EmbeddedId
private UserId id;

... other fields

@Embeddable
class UserId implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@Column(name = "user_id")
private int userId;
}
}


ProjectUser:



@Entity
@Table(name = "project_user")
public class ProjectUser implements Serializable {
@EmbeddedId
private ProjectUserId id;

... other fields

@Embeddable
class ProjectUserId implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "project_id", referencedColumnName = "project_id", insertable = false, updatable = false) })
private Project project;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false) })
private User user;
}
}


Before adding ProjectUser entity everything is working fine.

Now when I'm starting server it says:




Repeated column in mapping for entity: ProjectUser column: client_id
(should be mapped with insert="false" update="false")"}}




So, the question is how do I make this work?



EDIT:
Java application will be mostly REST services providing data. Database design is as is. It has logical sense and most of the business logic will be in database. We have people with very good DB knowledge working on this and it would not make much sense changing database design because of JPA/Hibernate limitations.







java hibernate jpa many-to-many






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 10:12







hyperion385

















asked Nov 22 '18 at 17:44









hyperion385hyperion385

8719




8719













  • Start with redesigning your schema. This doesn't really make any sense to me. For example, you have projectId for Project so you don't clientId as part of the primary key. Same with User. What is project_user trying to tell you? If it is just supposed to map Users to Projects and Projects to Users fine, but then what's the clientId for? This all looks like you started with a many-to-many and added Client and stuck clientId into everything. Define what you're trying to do at a more abstract level first.

    – K.Nicholas
    Nov 22 '18 at 18:45











  • I have edited the original question for some clarification. Thank you for the suggestion but I would really want to know if this is possible to map using current database schema.

    – hyperion385
    Nov 23 '18 at 10:15











  • "We have people with very good DB knowledge working on this" -- or not. I can visualize doing this with JPA but it still doesn't make sense so it's not worth it.

    – K.Nicholas
    Nov 23 '18 at 15:24





















  • Start with redesigning your schema. This doesn't really make any sense to me. For example, you have projectId for Project so you don't clientId as part of the primary key. Same with User. What is project_user trying to tell you? If it is just supposed to map Users to Projects and Projects to Users fine, but then what's the clientId for? This all looks like you started with a many-to-many and added Client and stuck clientId into everything. Define what you're trying to do at a more abstract level first.

    – K.Nicholas
    Nov 22 '18 at 18:45











  • I have edited the original question for some clarification. Thank you for the suggestion but I would really want to know if this is possible to map using current database schema.

    – hyperion385
    Nov 23 '18 at 10:15











  • "We have people with very good DB knowledge working on this" -- or not. I can visualize doing this with JPA but it still doesn't make sense so it's not worth it.

    – K.Nicholas
    Nov 23 '18 at 15:24



















Start with redesigning your schema. This doesn't really make any sense to me. For example, you have projectId for Project so you don't clientId as part of the primary key. Same with User. What is project_user trying to tell you? If it is just supposed to map Users to Projects and Projects to Users fine, but then what's the clientId for? This all looks like you started with a many-to-many and added Client and stuck clientId into everything. Define what you're trying to do at a more abstract level first.

– K.Nicholas
Nov 22 '18 at 18:45





Start with redesigning your schema. This doesn't really make any sense to me. For example, you have projectId for Project so you don't clientId as part of the primary key. Same with User. What is project_user trying to tell you? If it is just supposed to map Users to Projects and Projects to Users fine, but then what's the clientId for? This all looks like you started with a many-to-many and added Client and stuck clientId into everything. Define what you're trying to do at a more abstract level first.

– K.Nicholas
Nov 22 '18 at 18:45













I have edited the original question for some clarification. Thank you for the suggestion but I would really want to know if this is possible to map using current database schema.

– hyperion385
Nov 23 '18 at 10:15





I have edited the original question for some clarification. Thank you for the suggestion but I would really want to know if this is possible to map using current database schema.

– hyperion385
Nov 23 '18 at 10:15













"We have people with very good DB knowledge working on this" -- or not. I can visualize doing this with JPA but it still doesn't make sense so it's not worth it.

– K.Nicholas
Nov 23 '18 at 15:24







"We have people with very good DB knowledge working on this" -- or not. I can visualize doing this with JPA but it still doesn't make sense so it's not worth it.

– K.Nicholas
Nov 23 '18 at 15:24














1 Answer
1






active

oldest

votes


















0














The code below will let hibernate create a structure for your entities:



    @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "project_client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "project_id", referencedColumnName = "project_id", insertable = false, updatable = false) })
private Project project;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "user_client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false) })
private User user;


But to make a scheme as on the picture in your question, get rid of all these EmbeddedId. Use simple ids and add validation in your code, if you want project and user inside your ProjectUser have the same client_id.






share|improve this answer
























  • Thank you for the answer. I have edited original question for some clarification. Your solution with adding two more fields works for hibernate but it seems to much to add fields just to satisfy hibernate. So by the current database situation it seems there is no way to map this. Maybe it's time to reconsider some other persistence solution.

    – hyperion385
    Nov 23 '18 at 10:14













  • @hyperion385 of course you can map this! You just need to get rid of EmbeddedId, use simple ids.

    – Aleksandr Semyannikov
    Nov 23 '18 at 13:11











  • Well yes, that's what I've done today. But somehow I feel like this whole object mapping is then loosing it's purpose. But it's better then not working at all :)

    – hyperion385
    Nov 23 '18 at 14:02











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%2f53436036%2fjpa-hibernate-manytomany-relation-mapping-with-additional-fields%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














The code below will let hibernate create a structure for your entities:



    @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "project_client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "project_id", referencedColumnName = "project_id", insertable = false, updatable = false) })
private Project project;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "user_client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false) })
private User user;


But to make a scheme as on the picture in your question, get rid of all these EmbeddedId. Use simple ids and add validation in your code, if you want project and user inside your ProjectUser have the same client_id.






share|improve this answer
























  • Thank you for the answer. I have edited original question for some clarification. Your solution with adding two more fields works for hibernate but it seems to much to add fields just to satisfy hibernate. So by the current database situation it seems there is no way to map this. Maybe it's time to reconsider some other persistence solution.

    – hyperion385
    Nov 23 '18 at 10:14













  • @hyperion385 of course you can map this! You just need to get rid of EmbeddedId, use simple ids.

    – Aleksandr Semyannikov
    Nov 23 '18 at 13:11











  • Well yes, that's what I've done today. But somehow I feel like this whole object mapping is then loosing it's purpose. But it's better then not working at all :)

    – hyperion385
    Nov 23 '18 at 14:02
















0














The code below will let hibernate create a structure for your entities:



    @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "project_client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "project_id", referencedColumnName = "project_id", insertable = false, updatable = false) })
private Project project;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "user_client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false) })
private User user;


But to make a scheme as on the picture in your question, get rid of all these EmbeddedId. Use simple ids and add validation in your code, if you want project and user inside your ProjectUser have the same client_id.






share|improve this answer
























  • Thank you for the answer. I have edited original question for some clarification. Your solution with adding two more fields works for hibernate but it seems to much to add fields just to satisfy hibernate. So by the current database situation it seems there is no way to map this. Maybe it's time to reconsider some other persistence solution.

    – hyperion385
    Nov 23 '18 at 10:14













  • @hyperion385 of course you can map this! You just need to get rid of EmbeddedId, use simple ids.

    – Aleksandr Semyannikov
    Nov 23 '18 at 13:11











  • Well yes, that's what I've done today. But somehow I feel like this whole object mapping is then loosing it's purpose. But it's better then not working at all :)

    – hyperion385
    Nov 23 '18 at 14:02














0












0








0







The code below will let hibernate create a structure for your entities:



    @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "project_client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "project_id", referencedColumnName = "project_id", insertable = false, updatable = false) })
private Project project;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "user_client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false) })
private User user;


But to make a scheme as on the picture in your question, get rid of all these EmbeddedId. Use simple ids and add validation in your code, if you want project and user inside your ProjectUser have the same client_id.






share|improve this answer













The code below will let hibernate create a structure for your entities:



    @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
private Client client;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "project_client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "project_id", referencedColumnName = "project_id", insertable = false, updatable = false) })
private Project project;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "user_client_id", referencedColumnName = "client_id", insertable = false, updatable = false),
@JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false) })
private User user;


But to make a scheme as on the picture in your question, get rid of all these EmbeddedId. Use simple ids and add validation in your code, if you want project and user inside your ProjectUser have the same client_id.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 18:17









Aleksandr SemyannikovAleksandr Semyannikov

593217




593217













  • Thank you for the answer. I have edited original question for some clarification. Your solution with adding two more fields works for hibernate but it seems to much to add fields just to satisfy hibernate. So by the current database situation it seems there is no way to map this. Maybe it's time to reconsider some other persistence solution.

    – hyperion385
    Nov 23 '18 at 10:14













  • @hyperion385 of course you can map this! You just need to get rid of EmbeddedId, use simple ids.

    – Aleksandr Semyannikov
    Nov 23 '18 at 13:11











  • Well yes, that's what I've done today. But somehow I feel like this whole object mapping is then loosing it's purpose. But it's better then not working at all :)

    – hyperion385
    Nov 23 '18 at 14:02



















  • Thank you for the answer. I have edited original question for some clarification. Your solution with adding two more fields works for hibernate but it seems to much to add fields just to satisfy hibernate. So by the current database situation it seems there is no way to map this. Maybe it's time to reconsider some other persistence solution.

    – hyperion385
    Nov 23 '18 at 10:14













  • @hyperion385 of course you can map this! You just need to get rid of EmbeddedId, use simple ids.

    – Aleksandr Semyannikov
    Nov 23 '18 at 13:11











  • Well yes, that's what I've done today. But somehow I feel like this whole object mapping is then loosing it's purpose. But it's better then not working at all :)

    – hyperion385
    Nov 23 '18 at 14:02

















Thank you for the answer. I have edited original question for some clarification. Your solution with adding two more fields works for hibernate but it seems to much to add fields just to satisfy hibernate. So by the current database situation it seems there is no way to map this. Maybe it's time to reconsider some other persistence solution.

– hyperion385
Nov 23 '18 at 10:14







Thank you for the answer. I have edited original question for some clarification. Your solution with adding two more fields works for hibernate but it seems to much to add fields just to satisfy hibernate. So by the current database situation it seems there is no way to map this. Maybe it's time to reconsider some other persistence solution.

– hyperion385
Nov 23 '18 at 10:14















@hyperion385 of course you can map this! You just need to get rid of EmbeddedId, use simple ids.

– Aleksandr Semyannikov
Nov 23 '18 at 13:11





@hyperion385 of course you can map this! You just need to get rid of EmbeddedId, use simple ids.

– Aleksandr Semyannikov
Nov 23 '18 at 13:11













Well yes, that's what I've done today. But somehow I feel like this whole object mapping is then loosing it's purpose. But it's better then not working at all :)

– hyperion385
Nov 23 '18 at 14:02





Well yes, that's what I've done today. But somehow I feel like this whole object mapping is then loosing it's purpose. But it's better then not working at all :)

– hyperion385
Nov 23 '18 at 14:02




















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%2f53436036%2fjpa-hibernate-manytomany-relation-mapping-with-additional-fields%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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()