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;
}







2















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;

...
}









share|improve this question

























  • 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 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




















2















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;

...
}









share|improve this question

























  • 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 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
















2












2








2








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;

...
}









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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





















  • 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 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



















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














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
});


}
});














draft saved

draft discarded


















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
















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%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





















































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

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory