java - Splitting one DB association into several collections in Hibernate -
I am trying to improve in such a situation - a cash transfer (I mean the money that it carries ), Which is necessary for the quantity of each currency, and also an actual amount for each currency and I think that I do not have to make two separate classes, one for the required amount and the other for the actual amount. Then the implementation will look like this:
@Entity public class CashTransferCurrencyAmount {// id, @Column version and so many (length = 3) private string CurrencyCode; @ Original Private Big Decimal amount; @ManyToOne Personal Cash Transfer Cash Transfer; CashTransferCurrencyAmount & gt;} @Entity Public Category CashTransfer {// ID, Version and so on @OneToMany (mappedBy = "cashTransfer") set to personal < Required CurrencyAmountSet = New Hashet & lt; CashTransferAmountCurrency & gt; (); @OneToMany (Mapped = "Cash Transfer") Private Set & lt; Cash Transfer Credit Number & gt; Actual queryimountset = new hashset and lt; Cash TransfersAmountCourse & gt; (); }
But how does it know which collection is related to, is a CashTransferCurrencyAmount example? I have two ideas:
1 - Add a discriminator area to CashTransferCurrencyAmount:
public enum requestType {real, required} @Basic @Enumerated (EnumType.STRING) Private requestType Request Type; Add annotations to and @WHERE
to be stored in CashTransfer
. It is better for me <2> - Create two joining tables for mapping in a requested quantity and to map to a real quantity. I do not like this because I do not want many tables in my DB.
Is there any other way to achieve this? Do I correct this approach? And please do not tell me to give both the requested and the actual quantity in one unit. The real case is more complicated, with its CashTransferCurrencyAmount
has its collections, so it can not be resolved in this way
edit - for a request for a full story In the form - necessary (I think it should be 'requested') and is real, but now - there used to be two values in the CashTransferCurrencyAmount
each amount has its own collection - this amount Is divided into sects. So I need a collection of zodiac sign, each one has a collection of denominations. This type of currency amount and curious dementment seems to be for the people who are requested and for the real people.
After
Since you want to know the CashTransferCurrencyAmount example, which collection belongs to it, I think Based on that you want to make some arguments. The way I model your situation, he will use the heritage.
You are saying "I think that I am not wasted to make two different classes", but I will try to explain to you that you need it. You can use a "single table" inheritance type, so that you do not introduce additional tables in your DB, which you are trying to complete.
My shot will look something like this:
@Entity @Inheritance (strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn (name = "request_type", discriminatorType = DiscriminatorType.STRING) Public abstract currencyCodeTransferCurrencyAmount {// id, version and so on @clolumn (length = 3) private string currencyCode; @ Original Private Big Decimal amount; @ManyToOne Personal Cash Transfer Cash Transfer; } @ Entity @ Desirminator Value ("Required") Public Category Cash Transfer Karnataka Essential Cash TransfersCarmsimount {// Expected Exclusive Specific Goods Here} @ Entity @ Disimmeter Value ("Attual") Public Category Cash Transfer Crisis Capital Extension Cash Transfer Transfers Amount Is {// real unique exclusive stuff here} @interity public Las cash transfers {// ID, version and so on @OneToMany (map = "Cash Transfer") Private set required currency_AmountSet = new HashSet (); // Stackoverflow is removing my normal set! But this is actually the same as your code ... @OneToMany (mapped = "cache transfer") personal set realConnimetset = new hashset (); }
Comments
Post a Comment