[Hibernate-JIRA] Created: (HHH-3792) Entity Inheritance & abstract Field problem
by Miroslav Nachev (JIRA)
Entity Inheritance & abstract Field problem
-------------------------------------------
Key: HHH-3792
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3792
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.1
Environment: JDK6, MySQL
Reporter: Miroslav Nachev
I have one common class CustomerDiscountItem with 2 abstract methods:
@Entity
@Table(name = "customer_discount_items")//, catalog = "acacia_test", schema = "public")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(discriminatorType=DiscriminatorType.STRING, length=2, name="discriminator_id")
@NamedQueries({
@NamedQuery(
name = "CustomerDiscountItem.findByCustomerDiscount",
query = "SELECT t FROM CustomerDiscountItem t where t.customerDiscount = :customerDiscount")
})
public abstract class CustomerDiscountItem implements Serializable {
@JoinColumn(name = "customer_discount_id", referencedColumnName = "customer_discount_id", nullable = false)
@ManyToOne(optional = false)
public abstract CustomerDiscount getCustomerDiscount();
public abstract void setCustomerDiscount(CustomerDiscount customerDiscount);
This class is common for another 2 classes:
public class CustomerDiscountItemByCategory extends CustomerDiscountItem implements Serializable {
public class CustomerDiscountItemByProduct extends CustomerDiscountItem implements Serializable {
When I use named query "CustomerDiscountItem.findByCustomerDiscount" the result is not correct because in where clause only the first class is included:
where cdi_by_category.customer_discount_id=?
The correct where clause should be:
where cdi_by_category.customer_discount_id=? or cdi_by_product.customer_discount_id=?
The whole select statement generated by Hibernate is:
select
cdi.customer_discount_item_id,
cdi.discount_percent,
cdi.discriminator_id,
cdi_by_category.category_id,
cdi_by_category.customer_discount_id as category_cd_id,
cdi_by_category.include_heirs,
cdi_by_product.customer_discount_id as product_cd_id,
cdi_by_product.product_id,
case
when cdi_by_category.customer_discount_item_id is not null then 1
when cdi_by_product.customer_discount_item_id is not null then 2
when cdi.customer_discount_item_id is not null then 0
end as clazz_
from customer_discount_items cdi
left outer join customer_discount_items_by_categories cdi_by_category
on cdi.customer_discount_item_id=cdi_by_category.customer_discount_item_id
left outer join customer_discount_items_by_products cdi_by_product
on cdi.customer_discount_item_id=cdi_by_product.customer_discount_item_id
where cdi_by_category.customer_discount_id=?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years, 10 months
[Hibernate-JIRA] Commented: (HBX-609) SchemaUpdate with two identical DBs
by Brian Hayward (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HBX-609?page=co... ]
Brian Hayward commented on HBX-609:
-----------------------------------
>From what I've read, it looks like this logic is only used for validation purposes.
Correct me if I'm wrong here.
Many organizations use multiple schemas rather than separate databases with Oracle.
In scenarios like this, turning on validation isn't very useful.
> SchemaUpdate with two identical DBs
> -----------------------------------
>
> Key: HBX-609
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-609
> Project: Hibernate Tools
> Issue Type: Bug
> Environment: Hibernate 3.1.2, Oracle9i 9.2.0.5
> Reporter: Maciej Wisniewski
> Priority: Minor
>
> I have two Oracle users (A and B) on the same Oracle instance and trying to use one Hibernate application with schemaupdate (like in HHH-735) that creates all tables at first with user A and next with user B. The second failed with:
> <hibernate.util.JDBCExceptionReporter] could not get table metadata: BOOKMARK [???] java.sql.SQLException: ORA-01031: insufficient privileges
>
> After an investigation I've found that the problem is that in constructor of class org.hibernate.tool.hbm2ddl.TableMetadata schema is always A (even when connecting to user B). This variable gets its value from resultset created by method getTables from interface DatabaseMetaData (it is called from Configuration.generateSchemaUpdateScript). Oracle's thin driver implements this as an SQL:
> SELECT NULL AS table_cat,
> o.owner AS table_schem,
> o.object_name AS table_name,
> o.object_type AS table_type,
> NULL AS remarks
> FROM all_objects o
> WHERE o.owner LIKE ? ESCAPE '/'
> AND o.object_name LIKE ? ESCAPE '/'
> AND o.object_type IN ('xxx', 'TABLE')
> ORDER BY table_type, table_schem, table_name
> where the first "?" is unfortunatelly "%". So that table_schem is always A, even when asking for a table that belongs to B.
> Later Hibernate uses this fetched schema name to pass it to method DatabaseMetaData.getIndexInfo and it fails because it does no have privillages to A's index info.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years, 10 months