Posts

Showing posts from November, 2015

Play - The import views.html.index cannot be resolved

Problem: The import views.html.index cannot be resolved
Solution:  Add
target/scala-2.11/routes/maintarget/scala-2.11/twirl/main  to your project build path.
For some reason the option bellow wasn’t enough:
EclipseKeys.createSrc := EclipseCreateSrc.ValueSet(EclipseCreateSrc.ManagedClasses, EclipseCreateSrc.ManagedResources)

Hibernate - Avoid delete of all entity structure (cascade delete up)

Problem: When issuing an delete action Hibernate cascades up and deletes all the entity structure.

for(ShopProductSpec shopProductSpec: shopProductSpecs) {
            shopProductSpecDAO.delete(shopProductSpec);
        }

        ...
        Hibernate: delete from shop_product_brand where shop_product_id=?
        Hibernate: delete from shop_product_brand where shop_product_id=?
        Hibernate: delete from shop_product_uid where id=?
        Hibernate: delete from shop_product_image where id=?
        Hibernate: delete from shop_product_image where id=?
        Hibernate: delete from shop_product_image where id=?
        Hibernate: delete from shop_product_image where id=?
        Hibernate: delete from shop_product_image where id=?
        Hibernate: delete from shop_product_spec where id=?
        Hibernate: delete from shop_product_spec where id=?
        Hibernate: delete from shop_product_spec where id=?
        Hibernate: delete from shop_product_spec where id=?
        Hibern…

Hibernate - Criteria Inner Join

Build an Inner Join in Hibernate:
Solution: @Entity
@Table(name = "shop_product_uid")
public class ShopProductUid {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "shop_product_id")
private ShopProduct shopProduct;
@Column(name = "shop_product_uid")
private String shopProductUid;
@ManyToOne
@JoinColumn(name = "shop_product_uid_type_id")
private ShopProductUidType shopProductUidType;

Criteria criteria = session.createCriteria(ShopProductUid.class)
criteria.createAlias("shopProductUidType", "shopProductUidType") // inner join by default
.add(Restrictions.eq("shopProductUidType.typeId", parameterTypeId));