Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Hibernate

  Asked By: Adella    Date: Apr 17    Category: Java    Views: 602
  

I want to simulate TOP N SQL with HQL .There is no key word as I know.
I 'm not allowed to use setFirstResult and setMaxResult .I should write s.th in Query string.
Do you know How it is possible??
please send me any key word that you think can help me!!

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Hubba Akhtar     Answered On: Apr 17

I have an entity that has a field of type PlaceType. I don't want to have a equivalent table for it and i want that when Hibernate maps the columns entry to this field i could be able to get the farsi name to show it in form. How is it possible to do this.


@Entity
@Table
public class PostalCodeEntity implements Serializable{

private PlaceType type;

}

-------------------------------------------------------------------
public class PlaceType implements Serializable{
private static final long serialVersionUID = 1L;

private int type;
private String name;

private PlaceType(int type, String name) {
this.type = type;
this.name = name;
}

public int getType() {
return type;
}

public String getName() {
return name;
}

public static final PlaceType OFFICIAL = new PlaceType(1, "اداری");
public static final PlaceType RESIDENTIAL = new PlaceType(2, "مسکونی");
public static final PlaceType COMMERCIAL = new PlaceType(3, "تجاری");

}

 
Answer #2    Answered By: Sumitra 2004     Answered On: Apr 17

I don't know the main problem you're going to solve but as I guess from the solution, it does not look as the best one to me. But if you want to do it this way, do this:
Make the "type" field transient and add another field to your entity that stores its int value. You can now define an array in your PlaceType class that maps the int values to your final static fields and get the appropriate PlaceType in the getter method of the transient field in the entity.


@Entity
@Table
public class PostalCodeEntity implements Serializable{
@Transient
private PlaceType placeType;

private int type;

public PlaceType getPlaceType() {
return PlaceType.VALUES[type];
}
}

public class PlaceType implements Serializable{
private static final long serialVersionUID = 1L;

private int type;
private String name;

private PlaceType(int type, String name) {
this.type = type;
this.name = name;
}

public int getType() {
return type;
}

public String getName() {
return name;
}

public static final PlaceType[] VALUES = new PlaceType[] {
null, OFFICIAL, RESIDENTIAL, COMMERCIAL
};
public static final PlaceType OFFICIAL = new PlaceType(1, "اداری");
public static final PlaceType RESIDENTIAL = new PlaceType(2, "مسکونی");
public static final PlaceType COMMERCIAL = new PlaceType(3, "تجاری");

}

 
Answer #3    Answered By: Betty White     Answered On: Apr 17

I got your solution.
can I use "Custom Value Type" to solve this?

 
Answer #4    Answered By: Beverly Brooks     Answered On: Apr 17

As I know, you can. But remember that most of the times it's better to define a new entity for every attribute that maps to more than one column than to create a custom value type.

 
Didn't find what you were looking for? Find more on Hibernate Or get search suggestion and latest updates.




Tagged: