Hibernate / JPA: How to map two @Immutable entities (views of same table) with another entity by same...
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
There is a table ORDERS from which were created views ORDER_VIEW_A and ORDER_VIEW_B.
I have created entity classes OrderViewA and OrderViewB where in each of them is mapping on entity named 'TransactionRecord'.
It is @OneToOne relationship.
There is column ORDER_ID in TRANSACTION_RECORD table and field orderId in TransactionRecord entity.
Field orderId is same for OrderViewA.id and for OrderViewB.id, cause views are selected from the same table.
My question is, how to map in Hibernate two views in OneToOne relationship with another entity by same field.
My code looks like this and it doesn't work in any way, Hibernate always end up with:
org.hibernate.AnnotationException: Referenced property not a
(One|Many)ToOne: com.example.app.model.TransactionRecord.orderId in
mappedBy of com.example.app.model.views.OrderViewA.orderViewA
@Entity
@Immutable
@Table(name = "ORDER_VIEW_A")
public class OrderViewA {
@Id
@Column(name = "id")
private Long id;
...
@OneToOne(mappedBy = "orderId", fetch = FetchType.LAZY)
private IntegrationRecord orderARecord;
...
}
@Entity
@Immutable
@Table(name = "ORDER_VIEW_B")
public class OrderViewB {
@Id
@Column(name = "id")
private Long id;
...
@OneToOne(mappedBy = "orderId", fetch = FetchType.LAZY)
private IntegrationRecord orderBRecord;
...
}
@Entity
@Table(name = "TRANSACTION_RECORD")
public class TransactionRecord {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "order_id")
private Long orderId;
...
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "order_id")
private OrderViewA orderViewA;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "order_id")
private OrderViewB orderViewB;
...
}
java hibernate spring-boot jpa
add a comment |
There is a table ORDERS from which were created views ORDER_VIEW_A and ORDER_VIEW_B.
I have created entity classes OrderViewA and OrderViewB where in each of them is mapping on entity named 'TransactionRecord'.
It is @OneToOne relationship.
There is column ORDER_ID in TRANSACTION_RECORD table and field orderId in TransactionRecord entity.
Field orderId is same for OrderViewA.id and for OrderViewB.id, cause views are selected from the same table.
My question is, how to map in Hibernate two views in OneToOne relationship with another entity by same field.
My code looks like this and it doesn't work in any way, Hibernate always end up with:
org.hibernate.AnnotationException: Referenced property not a
(One|Many)ToOne: com.example.app.model.TransactionRecord.orderId in
mappedBy of com.example.app.model.views.OrderViewA.orderViewA
@Entity
@Immutable
@Table(name = "ORDER_VIEW_A")
public class OrderViewA {
@Id
@Column(name = "id")
private Long id;
...
@OneToOne(mappedBy = "orderId", fetch = FetchType.LAZY)
private IntegrationRecord orderARecord;
...
}
@Entity
@Immutable
@Table(name = "ORDER_VIEW_B")
public class OrderViewB {
@Id
@Column(name = "id")
private Long id;
...
@OneToOne(mappedBy = "orderId", fetch = FetchType.LAZY)
private IntegrationRecord orderBRecord;
...
}
@Entity
@Table(name = "TRANSACTION_RECORD")
public class TransactionRecord {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "order_id")
private Long orderId;
...
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "order_id")
private OrderViewA orderViewA;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "order_id")
private OrderViewB orderViewB;
...
}
java hibernate spring-boot jpa
Which@Immutable
is this?
– chrylis
Jan 3 at 14:37
org.hibernate.annotations.Immutable
– Järvi
Jan 3 at 14:47
Probably a long-shot, but try changing the@OneToOne(mappedBy
in both views to theorderViewA
andorderViewB
, rather than orderId, and havereferencedColumnName = "order_id"
. I'm not even sure you can have multiple joins on the same column in Hibernate.
– coladict
Jan 4 at 10:24
add a comment |
There is a table ORDERS from which were created views ORDER_VIEW_A and ORDER_VIEW_B.
I have created entity classes OrderViewA and OrderViewB where in each of them is mapping on entity named 'TransactionRecord'.
It is @OneToOne relationship.
There is column ORDER_ID in TRANSACTION_RECORD table and field orderId in TransactionRecord entity.
Field orderId is same for OrderViewA.id and for OrderViewB.id, cause views are selected from the same table.
My question is, how to map in Hibernate two views in OneToOne relationship with another entity by same field.
My code looks like this and it doesn't work in any way, Hibernate always end up with:
org.hibernate.AnnotationException: Referenced property not a
(One|Many)ToOne: com.example.app.model.TransactionRecord.orderId in
mappedBy of com.example.app.model.views.OrderViewA.orderViewA
@Entity
@Immutable
@Table(name = "ORDER_VIEW_A")
public class OrderViewA {
@Id
@Column(name = "id")
private Long id;
...
@OneToOne(mappedBy = "orderId", fetch = FetchType.LAZY)
private IntegrationRecord orderARecord;
...
}
@Entity
@Immutable
@Table(name = "ORDER_VIEW_B")
public class OrderViewB {
@Id
@Column(name = "id")
private Long id;
...
@OneToOne(mappedBy = "orderId", fetch = FetchType.LAZY)
private IntegrationRecord orderBRecord;
...
}
@Entity
@Table(name = "TRANSACTION_RECORD")
public class TransactionRecord {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "order_id")
private Long orderId;
...
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "order_id")
private OrderViewA orderViewA;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "order_id")
private OrderViewB orderViewB;
...
}
java hibernate spring-boot jpa
There is a table ORDERS from which were created views ORDER_VIEW_A and ORDER_VIEW_B.
I have created entity classes OrderViewA and OrderViewB where in each of them is mapping on entity named 'TransactionRecord'.
It is @OneToOne relationship.
There is column ORDER_ID in TRANSACTION_RECORD table and field orderId in TransactionRecord entity.
Field orderId is same for OrderViewA.id and for OrderViewB.id, cause views are selected from the same table.
My question is, how to map in Hibernate two views in OneToOne relationship with another entity by same field.
My code looks like this and it doesn't work in any way, Hibernate always end up with:
org.hibernate.AnnotationException: Referenced property not a
(One|Many)ToOne: com.example.app.model.TransactionRecord.orderId in
mappedBy of com.example.app.model.views.OrderViewA.orderViewA
@Entity
@Immutable
@Table(name = "ORDER_VIEW_A")
public class OrderViewA {
@Id
@Column(name = "id")
private Long id;
...
@OneToOne(mappedBy = "orderId", fetch = FetchType.LAZY)
private IntegrationRecord orderARecord;
...
}
@Entity
@Immutable
@Table(name = "ORDER_VIEW_B")
public class OrderViewB {
@Id
@Column(name = "id")
private Long id;
...
@OneToOne(mappedBy = "orderId", fetch = FetchType.LAZY)
private IntegrationRecord orderBRecord;
...
}
@Entity
@Table(name = "TRANSACTION_RECORD")
public class TransactionRecord {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "order_id")
private Long orderId;
...
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "order_id")
private OrderViewA orderViewA;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "order_id")
private OrderViewB orderViewB;
...
}
java hibernate spring-boot jpa
java hibernate spring-boot jpa
edited Jan 3 at 14:28
ClickThisNick
2,08282550
2,08282550
asked Jan 3 at 14:23
JärviJärvi
133
133
Which@Immutable
is this?
– chrylis
Jan 3 at 14:37
org.hibernate.annotations.Immutable
– Järvi
Jan 3 at 14:47
Probably a long-shot, but try changing the@OneToOne(mappedBy
in both views to theorderViewA
andorderViewB
, rather than orderId, and havereferencedColumnName = "order_id"
. I'm not even sure you can have multiple joins on the same column in Hibernate.
– coladict
Jan 4 at 10:24
add a comment |
Which@Immutable
is this?
– chrylis
Jan 3 at 14:37
org.hibernate.annotations.Immutable
– Järvi
Jan 3 at 14:47
Probably a long-shot, but try changing the@OneToOne(mappedBy
in both views to theorderViewA
andorderViewB
, rather than orderId, and havereferencedColumnName = "order_id"
. I'm not even sure you can have multiple joins on the same column in Hibernate.
– coladict
Jan 4 at 10:24
Which
@Immutable
is this?– chrylis
Jan 3 at 14:37
Which
@Immutable
is this?– chrylis
Jan 3 at 14:37
org.hibernate.annotations.Immutable
– Järvi
Jan 3 at 14:47
org.hibernate.annotations.Immutable
– Järvi
Jan 3 at 14:47
Probably a long-shot, but try changing the
@OneToOne(mappedBy
in both views to the orderViewA
and orderViewB
, rather than orderId, and have referencedColumnName = "order_id"
. I'm not even sure you can have multiple joins on the same column in Hibernate.– coladict
Jan 4 at 10:24
Probably a long-shot, but try changing the
@OneToOne(mappedBy
in both views to the orderViewA
and orderViewB
, rather than orderId, and have referencedColumnName = "order_id"
. I'm not even sure you can have multiple joins on the same column in Hibernate.– coladict
Jan 4 at 10:24
add a comment |
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/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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54024199%2fhibernate-jpa-how-to-map-two-immutable-entities-views-of-same-table-with-a%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
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54024199%2fhibernate-jpa-how-to-map-two-immutable-entities-views-of-same-table-with-a%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Which
@Immutable
is this?– chrylis
Jan 3 at 14:37
org.hibernate.annotations.Immutable
– Järvi
Jan 3 at 14:47
Probably a long-shot, but try changing the
@OneToOne(mappedBy
in both views to theorderViewA
andorderViewB
, rather than orderId, and havereferencedColumnName = "order_id"
. I'm not even sure you can have multiple joins on the same column in Hibernate.– coladict
Jan 4 at 10:24