|
Hibernate example source code file (AssociationOverrideTest.java)
The Hibernate AssociationOverrideTest.java source codepackage org.hibernate.test.annotations.override; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.Transaction; import org.junit.Test; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.test.util.SchemaUtil; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * @author Emmanuel Bernard */ public class AssociationOverrideTest extends BaseCoreFunctionalTestCase { @Test public void testOverriding() throws Exception { Location paris = new Location(); paris.setName( "Paris" ); Location atlanta = new Location(); atlanta.setName( "Atlanta" ); Trip trip = new Trip(); trip.setFrom( paris ); //trip.setTo( atlanta ); Session s = openSession(); Transaction tx = s.beginTransaction(); s.persist( paris ); s.persist( atlanta ); try { s.persist( trip ); s.flush(); fail( "Should be non nullable" ); } catch (HibernateException e) { //success } finally { tx.rollback(); s.close(); } } @Test public void testDottedNotation() throws Exception { assertTrue( SchemaUtil.isTablePresent( "Employee", configuration() ) ); assertTrue( "Overridden @JoinColumn fails", SchemaUtil.isColumnPresent( "Employee", "fld_address_fk", configuration() ) ); assertTrue( "Overridden @JoinTable name fails", SchemaUtil.isTablePresent( "tbl_empl_sites", configuration() ) ); assertTrue( "Overridden @JoinTable with default @JoinColumn fails", SchemaUtil.isColumnPresent( "tbl_empl_sites", "employee_id", configuration() ) ); assertTrue( "Overridden @JoinTable.inverseJoinColumn fails", SchemaUtil.isColumnPresent( "tbl_empl_sites", "to_website_fk", configuration() ) ); Session s = openSession(); Transaction tx = s.beginTransaction(); ContactInfo ci = new ContactInfo(); Addr address = new Addr(); address.setCity("Boston"); address.setCountry("USA"); address.setState("MA"); address.setStreet("27 School Street"); address.setZipcode("02108"); ci.setAddr(address); List<PhoneNumber> phoneNumbers = new ArrayList(); PhoneNumber num = new PhoneNumber(); num.setNumber(5577188); Employee e = new Employee(); Collection employeeList = new ArrayList(); employeeList.add(e); e.setContactInfo(ci); num.setEmployees(employeeList); phoneNumbers.add(num); ci.setPhoneNumbers(phoneNumbers); SocialTouchPoints socialPoints = new SocialTouchPoints(); List<SocialSite> sites = new ArrayList Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate AssociationOverrideTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.