• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sample code discrimination feature.

 
jani basha
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i need to work with discrimination feature in hibernate where i have to get the data based on one column.
can anybody give the sample code for this?? plzzzzzzz
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The documentation covers this. Have you read through that? What are you stuck on?
[ October 23, 2008: Message edited by: Paul Sturrock ]
 
jani basha
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am new to hibernate...i was given the task to find out how discrimination works and what is the purpose. i was going through the documentation but not able to find out proper one which give sample and explanation. what i need to do is i want to get the data basing on discrimination given.
can you please help me out???
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The section on inheritence mapping is where you need to look. There are examples of three strategies, including using discriminators.

Have a read through this. It should be enough to get you going in the right direction. If you have any more questions, ask them here and someone will help if they can.
 
jani basha
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i have gone through the docs and tried to do a sample.
but it was not successful. mean to say i am not able to save objects using table per class methodology.

i have two classes(creditcard and bankaccount) inherited from a single class(billing details) and a single table with name billingdetails.
when i try to save some data its not saved. its not showing any error also.
here i am sending the mappings and other files for your ref.
please help me.

<hibernate-mapping>
<class name="hibernate.BillingDetails" table="BILLINGDETAILS" schema="SCOTT">
<id name="billingId" column="BILLING_DETAILS_ID">
<generator class="assigned"></generator>
</id>
<discriminator column="BILLING_DETAILS_TYPE" type="string"></discriminator>
<property name="owner" column="OWNER"></property>
<property name="billingNumber" column="BILLINGNUMBER"></property>
<property name="createdOn" column="CREATEDON"></property>
<subclass name="hibernate.CreditCard" discriminator-value="CC">
<property name="type" column="CC_TYPE"></property>
<property name="expMonth" column="CC_EXPMONTH"></property>
<property name="expYear" column="CC_EXPYEAR"></property>
</subclass>
<subclass name="hibernate.BankAccount" discriminator-value="BA">
<property name="bankName" column="BA_BANKNAME"></property>
<property name="bankSwift" column="BA_BANKSWIFT"></property>
</subclass>
</class>
</hibernate-mapping>


BankAccount ba=new BankAccount();
ba.setBankName("ICICI");
ba.setBankSwift("asjdf");
ba.setBillingId(new Integer(2));
ba.setBillingNumber("1111");
ba.setCreatedOn(new Date().toString());
ba.setOwner("somename");
session.save(ba);

where i am doing wrong???
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to remember that nothing happens in a relational database outside of a transaction.

Have a read of that documentation. Also have a search through this forum, this is a question that has been asked many times before.
 
jani basha
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Paul Sturrock for you reply.
actually i was using transaction also it may be missed in copying it.

ok fine .now its working fine the mistake i have done is with the date field which i have taken as String at java side and Date type on db side.

just i have changed to Date type its working fine.now able to persist data and retrieve data with discriminator.

thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic