en , I get it,let me write more words:
I have two business object: Contract and Product, contract is make out when businss trade is to be in process, product is the product of the contract, that is :which goods i will sell out in this contract. So one contract may contains one or more products (there is a contractId field in the product).
My old idea is : create two entity(table) in the database,then create a view entity:
create view ContractAndProduct as select c.contractShorter,c.contractNumber,p.productName from Contrat c,Product p where p.contractId=c.contractid;
then mapping three entity:Contract.hbm,Product.hbm,ContractAndProduct.hbm,
and I also get three Java Object:
Contract.java,Product.java,ContractAndProduct.java
If I want to get the contracts that contain specify product,I can submit a query to ContractAndProduct.java, the hql may like this:
from ContractAndProduct cp where cp.productName ='ABC';
then I will show the search result on the web page.
It is my OLD idea,my new idea is to create a view entity in hibernate,not in database,so the database only exist two table entity:Contrat and Product,the view ContractAndProduct exist in hibernate ,not in database, in this case ,i can write the hql like old:
from ContractAndProduct cp where cp.productName ='ABC';
that is what I mean about "a view of hibernate" , but I dont know how to get it work.
notice: my system is more complex than it , I MUST get only A java object to query, so do not tell me like this : " select c.contractNumber,p.productName from ..........."
I think I have describ my question clearly ,may you have patience.
Thank you very much !!!
tenwit wrote:
I think they want you to paraphrase your question so that they can understand it. Noone can understand your original question.
What do you mean by "view of the database"? Do you want to replace your schema entirely? Do you want to change how your java app talks to the database, but keep the existing tables and data? Either way, read the reference docs (on
www.hibernate.org) or buy Hibernate In Action.. when it's out for Hibernate 3.