sql - dynamic joincolumn and join clause with variables -


I have a unidirectional one-to-one relation. What I want to achieve is either using

  • creating a fixture on the class and sending the variable for it so that I can change the add column (to change the join column) Any other suggestion can also be welcomed)
  • Ignore the first section created by Hibernate and make specific O segment using the criteria in the lower part of the question.

My query that works in SQL Manager:

  SELECT d.Description, d.AccountId, d.PartnerId, a.FormattedName InvoiceDesigns D INNER Join the UserAccount at a.id = case when D. Partner ID! = -1 and d.AccountId = 1 then D. Partner ID WHEN d.PartnerId = 1 THEN d.AccountId ELSE 1 END where d.AccountId = 1 or PartnerId = 1  

The functional query runs in SQL Manager, not in hibernate. This is what I want to achieve, I want hibernate to create a query like this.
When an account says an example, pasted with an ID = 1, the design shows that they are
A) Designer of the partner ID is not 1 and 1 is the account ID1, which means That is created by the partner of that account and will display the partner's formatted name.
This is for general accounts, when looking at their available devices. If a partner has designed them, then they will see the name of that partner.

B) is equal to PartnerId account ID, which means that it is a collaborative design and formatted. The account is designed for the related design will be displayed.
The Partners account is for viewing the design they made.

C) is designed directly by the design account, so your name will display for general accounts and self-made designs.

When I only want to use Account ID or Partner ID, the normal session is working fine, but I have to change the column to get the related formatted name. I have tried @ where, @filler, @Join columnAfformula but I was not able to get this question.

with my class @ where originally this looks like:

Design class:

@ id @ generated value (strategy = GenerationType .IDENTITY) @column (name = "id") int id; @column (name = "account id") int account id; @column (name = "partner id") int partner id; @OneToOne (fetch = FetchType.LAZY) @JoinColumn (name = "account id", referenced column name = "id", insertable = false, updatable = false, nullable = true) @ where (segment = "case" + "WHEN PartnerId! -1 and account id =: account-end THEN partner ID "+" WHEN partner id =: account id then account command "+" ELSE: accountId "+" END ") account data account;

Account class:

  @ id @ generatedValue (strategy = GenerationType.IDENTITY) @column (name = "id") int id; @column (name = "FormattedName") string formatted name; Here you can see that I want to send an ID to query as "parameter: using account:", which will be used to define the usage column. .  

This question: really does something like that. That is why I paid attention to

Add: I found anything with parameters

  criteria = session. Secretariat (invoice design data class, "design"); Criteria.createCriteria ("design.account", "ACC", JointType.LIFTUAtzone, restriction.Eccproperty ("ACC", "Design PARTNERID")); Invoice design list = criteria List ();  

But this does not ignore the first condition and adds additional condition on the clause on the use of Android. I had removed the columns from one to several people to ignore the first condition, but it is not. Produced query:

  This left external use from invoice design is included in UserAccount acc1_ this_.account_id = acc1_.id and (acc1_.id = this_.PartnerId)  

Thanks in advance

You can try to extend the case statement:

  select d. Details, D. Account ID, D. Join partner INDER user from partner id, SE (* SELECT *, case when the participant ID! = -1 and account id = 1, partner IWN partner ID = 1 then accountind 1 ELSE 1 EDID insight design SmartID) Edit .id = d.SmartID WHERE d.AccountId = 1 or PartnerId = 1  

Edit: It basically leaves you without any in-line query straightening with it Conditional current statement.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -