java - JPA/Hibernate how to join a particular field from an entity into a different entity -


Assume that we have unit A and unit B, with each corresponding table, A and B.

The unit A is a hotel and its ID and many areas such as country, city, postal code etc. are included.

Unit B is an ID in a description list (which is similar to that of unit A) and other 2 fields, languages ​​and descriptions.

I am creating the following query in my DAO:

  query query = getEntityManager (). CreateQuery ("FROM" + Type.getSimpleName () + "WHERE city =: city paras and country =: countrymaps"); Query.setParameter ("city paragraph", city paragraph); Query.setParameter ("Countryprint", CountryNameParam); Query.setMaxResults (numberOfResults); & Lt; HotelDto & gt; HotelMap = query.getResultList (); ListResponseModel Results = New ListResponseModel (); Result.setHotelMap (Hotelmap); Return result. GetHotelMap () Size ()> 0? Results: zero;  

Entity A, the hotel unit looks like this:

  @taintyTable (name = "propertyList", uniqueConstraints = {@UniqueConstraint (columnNames = "Hotel-id")} Public-class hotels, Serial Job, Entrepreneur ID & lt; Long & gt; {Private Stable Last Long SerialVersionUID = 1L; @ ID @ Generated Values ​​@ Column (name = "Hotel ID") Private Long Hotel Id; @ Column (name = "name") private string name; @column (name = "address") private string address; @column (name = "city") private string city; @column (name = "stateprivance") private string state province; @column (name = "postal code") private string postal code; @column (name = "country") private string country; @OneToOne (fetch = FetchType.LAZY) @PrimaryKeyJoinColumn (name = "propertyhotelid") Description of personal property property details; [...]  

Entity B, description, looks like this:

  @tainty @Table (name = "propertyDescriptionList", uniqueConstraints = { @UniqueConstraint (columnNames = "HotelID")} Public Class Property Transcription Tool Serializable, EntityWithId & lt; Long & gt; {Private Stable Last Long SerialVersionUID = 1L; @ Id @ column (name = "hotel id", exclusive = true, drain = false) Private long hotel id; @column (name = "property description") private string property description;  

The issue is that once I set the result, one unit will look like this:

  Hotel ID: 124125, Name: " Random Hotel ", Address:" Some Address ", City:" Shambala ", Postal Code:" W2 3Na ", Country:" Nevverland ", -Property Description: {Hotel ID: 105496, Property Details:" Details here Insert Bla bla bla. " }}  

What do I get:

  Hotel ID: 124125, Name: "Random Hotel", Address: "Some Address", City: "Shambala", Postal Code: "W2 3A A", Country: "Nevverland", Property Description: "Enter Details Here Blah Blah." }  

Since I am only interested in the description which is a string, and not having the whole object, which also has an ID (a duplicate).

What would be the best way to achieve this?

From your question, think of what you are looking for to map a table of two tables to one The way? If so, you can do this with the @ Secondary Table: The string 'description' will just become the area of ​​your hotel unit. @ Secondary template (name = "property descript list", pkJoinColumns = @

PrimaryKeyJoinColumn (name = "Hotel ID"), Unique Conference = {@ Unique Consultant (column name = "Hotel ID"}} Public Category Hotel Serializable {@Id @Column (name = "HotelID") Private Long Hotel Id; @column (name = "property description", table = "attribute list") private string property description; }

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -