/* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.test.annotations.notfound; import org.hibernate.Session; import org.hibernate.Transaction; import org.junit.Test; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import static org.junit.Assert.assertNull; /** * @author Emmanuel Bernard */ public class NotFoundTest extends BaseCoreFunctionalTestCase { @Test public void testManyToOne() throws Exception { Currency euro = new Currency(); euro.setName( "Euro" ); Coin fiveC = new Coin(); fiveC.setName( "Five cents" ); fiveC.setCurrency( euro ); Session s = openSession(); s.getTransaction().begin(); s.persist( euro ); s.persist( fiveC ); s.getTransaction().commit(); s.clear(); Transaction tx = s.beginTransaction(); euro = (Currency) s.get( Currency.class, euro.getId() ); s.delete( euro ); tx.commit(); s.clear(); tx = s.beginTransaction(); fiveC = (Coin) s.get( Coin.class, fiveC.getId() ); assertNull( fiveC.getCurrency() ); s.delete( fiveC ); tx.commit(); s.close(); } @Override protected Class[] getAnnotatedClasses() { return new Class[] { Coin.class, Currency.class }; } }