Hibernate filters
up vote
3
down vote
favorite
I've been trying to implement hibernate filters however I seem to be getting some strange results.
When I get a list the first result of Ship Entity seems to have gotten the correct BuildFormula when I move to the next object the BuildFormula is incorrect.
1st: itemType = Ship
2nd: itemType = Building
Session session = entityManager.unwrap(Session.class);
session.enableFilter(BY_USER_ID_PLANET_ID_STAR_ID)
.setParameter(USER_ID, UserInfoHolder.getLocation().getUserId())
.setParameter(PLANET_ID, UserInfoHolder.getLocation().getPlanetId())
.setParameter(STAR_ID, UserInfoHolder.getLocation().getStarId());
session.enableFilter(TYPE).setParameter("itemType", SHIP);
List<Ship> buildingList = session.createQuery("FROM Ship", Ship.class).getResultList();
return buildingList.stream().map(this::convertToVO).collect(Collectors.toList());
The main entity
@Data
@Table
@Entity
public class Ship
public static final String SHIP = "ship";
@Id
private Integer id;
private String name;
private String description;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "itemId", referencedColumnName="id", insertable = false, updatable = false)
@Filter(name = "byType", condition = "item_type = :itemType")
private List<BuildFormulas> buildFormulas;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "shipId", insertable = false, updatable = false)
@Filter(name = "byUserIdPlanetIdStarId")
private List<ShipToUser> shipToUser;
And the BuildFormulas class
@Data
@Entity
@FilterDef(
name = "byType",
defaultCondition = "item_type = :itemType",
parameters =
@ParamDef(name = "itemType", type = "string")
)
public class BuildFormulas
@Id
private Integer itemId;
private String metalCost;
private String crystalCost;
private String deuteriumCost;
private String energyCost;
private String speed;
private String itemType;
And the ShipToUser
@Data
@Entity
@FilterDef(
name = "byUserIdPlanetIdStarId",
defaultCondition = "user_id = :userId AND planet_id = :planetId AND star_id = :starId",
parameters =
@ParamDef(name = "userId", type = "int"),
@ParamDef(name = "planetId", type = "string"),
@ParamDef(name = "starId", type = "string")
)
public class ShipToUser
@EmbeddedId
private ShipToUserKey shipToUserKey;
private int amount;
Any help would be appreciated to unlocking this mystery.
java spring hibernate
add a comment |
up vote
3
down vote
favorite
I've been trying to implement hibernate filters however I seem to be getting some strange results.
When I get a list the first result of Ship Entity seems to have gotten the correct BuildFormula when I move to the next object the BuildFormula is incorrect.
1st: itemType = Ship
2nd: itemType = Building
Session session = entityManager.unwrap(Session.class);
session.enableFilter(BY_USER_ID_PLANET_ID_STAR_ID)
.setParameter(USER_ID, UserInfoHolder.getLocation().getUserId())
.setParameter(PLANET_ID, UserInfoHolder.getLocation().getPlanetId())
.setParameter(STAR_ID, UserInfoHolder.getLocation().getStarId());
session.enableFilter(TYPE).setParameter("itemType", SHIP);
List<Ship> buildingList = session.createQuery("FROM Ship", Ship.class).getResultList();
return buildingList.stream().map(this::convertToVO).collect(Collectors.toList());
The main entity
@Data
@Table
@Entity
public class Ship
public static final String SHIP = "ship";
@Id
private Integer id;
private String name;
private String description;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "itemId", referencedColumnName="id", insertable = false, updatable = false)
@Filter(name = "byType", condition = "item_type = :itemType")
private List<BuildFormulas> buildFormulas;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "shipId", insertable = false, updatable = false)
@Filter(name = "byUserIdPlanetIdStarId")
private List<ShipToUser> shipToUser;
And the BuildFormulas class
@Data
@Entity
@FilterDef(
name = "byType",
defaultCondition = "item_type = :itemType",
parameters =
@ParamDef(name = "itemType", type = "string")
)
public class BuildFormulas
@Id
private Integer itemId;
private String metalCost;
private String crystalCost;
private String deuteriumCost;
private String energyCost;
private String speed;
private String itemType;
And the ShipToUser
@Data
@Entity
@FilterDef(
name = "byUserIdPlanetIdStarId",
defaultCondition = "user_id = :userId AND planet_id = :planetId AND star_id = :starId",
parameters =
@ParamDef(name = "userId", type = "int"),
@ParamDef(name = "planetId", type = "string"),
@ParamDef(name = "starId", type = "string")
)
public class ShipToUser
@EmbeddedId
private ShipToUserKey shipToUserKey;
private int amount;
Any help would be appreciated to unlocking this mystery.
java spring hibernate
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I've been trying to implement hibernate filters however I seem to be getting some strange results.
When I get a list the first result of Ship Entity seems to have gotten the correct BuildFormula when I move to the next object the BuildFormula is incorrect.
1st: itemType = Ship
2nd: itemType = Building
Session session = entityManager.unwrap(Session.class);
session.enableFilter(BY_USER_ID_PLANET_ID_STAR_ID)
.setParameter(USER_ID, UserInfoHolder.getLocation().getUserId())
.setParameter(PLANET_ID, UserInfoHolder.getLocation().getPlanetId())
.setParameter(STAR_ID, UserInfoHolder.getLocation().getStarId());
session.enableFilter(TYPE).setParameter("itemType", SHIP);
List<Ship> buildingList = session.createQuery("FROM Ship", Ship.class).getResultList();
return buildingList.stream().map(this::convertToVO).collect(Collectors.toList());
The main entity
@Data
@Table
@Entity
public class Ship
public static final String SHIP = "ship";
@Id
private Integer id;
private String name;
private String description;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "itemId", referencedColumnName="id", insertable = false, updatable = false)
@Filter(name = "byType", condition = "item_type = :itemType")
private List<BuildFormulas> buildFormulas;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "shipId", insertable = false, updatable = false)
@Filter(name = "byUserIdPlanetIdStarId")
private List<ShipToUser> shipToUser;
And the BuildFormulas class
@Data
@Entity
@FilterDef(
name = "byType",
defaultCondition = "item_type = :itemType",
parameters =
@ParamDef(name = "itemType", type = "string")
)
public class BuildFormulas
@Id
private Integer itemId;
private String metalCost;
private String crystalCost;
private String deuteriumCost;
private String energyCost;
private String speed;
private String itemType;
And the ShipToUser
@Data
@Entity
@FilterDef(
name = "byUserIdPlanetIdStarId",
defaultCondition = "user_id = :userId AND planet_id = :planetId AND star_id = :starId",
parameters =
@ParamDef(name = "userId", type = "int"),
@ParamDef(name = "planetId", type = "string"),
@ParamDef(name = "starId", type = "string")
)
public class ShipToUser
@EmbeddedId
private ShipToUserKey shipToUserKey;
private int amount;
Any help would be appreciated to unlocking this mystery.
java spring hibernate
I've been trying to implement hibernate filters however I seem to be getting some strange results.
When I get a list the first result of Ship Entity seems to have gotten the correct BuildFormula when I move to the next object the BuildFormula is incorrect.
1st: itemType = Ship
2nd: itemType = Building
Session session = entityManager.unwrap(Session.class);
session.enableFilter(BY_USER_ID_PLANET_ID_STAR_ID)
.setParameter(USER_ID, UserInfoHolder.getLocation().getUserId())
.setParameter(PLANET_ID, UserInfoHolder.getLocation().getPlanetId())
.setParameter(STAR_ID, UserInfoHolder.getLocation().getStarId());
session.enableFilter(TYPE).setParameter("itemType", SHIP);
List<Ship> buildingList = session.createQuery("FROM Ship", Ship.class).getResultList();
return buildingList.stream().map(this::convertToVO).collect(Collectors.toList());
The main entity
@Data
@Table
@Entity
public class Ship
public static final String SHIP = "ship";
@Id
private Integer id;
private String name;
private String description;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "itemId", referencedColumnName="id", insertable = false, updatable = false)
@Filter(name = "byType", condition = "item_type = :itemType")
private List<BuildFormulas> buildFormulas;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "shipId", insertable = false, updatable = false)
@Filter(name = "byUserIdPlanetIdStarId")
private List<ShipToUser> shipToUser;
And the BuildFormulas class
@Data
@Entity
@FilterDef(
name = "byType",
defaultCondition = "item_type = :itemType",
parameters =
@ParamDef(name = "itemType", type = "string")
)
public class BuildFormulas
@Id
private Integer itemId;
private String metalCost;
private String crystalCost;
private String deuteriumCost;
private String energyCost;
private String speed;
private String itemType;
And the ShipToUser
@Data
@Entity
@FilterDef(
name = "byUserIdPlanetIdStarId",
defaultCondition = "user_id = :userId AND planet_id = :planetId AND star_id = :starId",
parameters =
@ParamDef(name = "userId", type = "int"),
@ParamDef(name = "planetId", type = "string"),
@ParamDef(name = "starId", type = "string")
)
public class ShipToUser
@EmbeddedId
private ShipToUserKey shipToUserKey;
private int amount;
Any help would be appreciated to unlocking this mystery.
java spring hibernate
java spring hibernate
edited 2 days ago
Gayan Mettananda
1355
1355
asked 2 days ago
VortexFX
516
516
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53225221%2fhibernate-filters%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password