📄 targettest.java
字号:
//$Id: $
package org.hibernate.test.annotations.target;
import org.hibernate.test.annotations.TestCase;
import org.hibernate.Session;
/**
* @author Emmanuel Bernard
*/
public class TargetTest extends TestCase {
public void testTargetOnEmbedded() throws Exception {
Session s = openSession();
s.getTransaction().begin();
Luggage l = new LuggageImpl();
l.setHeight( 12 );
l.setWidth( 12 );
Owner o = new OwnerImpl();
o.setName( "Emmanuel" );
l.setOwner( o );
s.persist( l );
s.flush();
s.clear();
l = (Luggage) s.get(LuggageImpl.class, ( (LuggageImpl) l).getId() );
assertEquals( "Emmanuel", l.getOwner().getName() );
s.getTransaction().rollback();
s.close();
}
public void testTargetOnMapKey() throws Exception {
Session s = openSession();
s.getTransaction().begin();
Luggage l = new LuggageImpl();
l.setHeight( 12 );
l.setWidth( 12 );
Size size = new SizeImpl();
size.setName( "S" );
Owner o = new OwnerImpl();
o.setName( "Emmanuel" );
l.setOwner( o );
s.persist( l );
Brand b = new Brand();
s.persist( b );
b.getLuggagesBySize().put( size, l );
s.flush();
s.clear();
b = (Brand) s.get(Brand.class, b.getId() );
assertEquals( "S", b.getLuggagesBySize().keySet().iterator().next().getName() );
s.getTransaction().rollback();
s.close();
}
public void testTargetOnMapKeyManyToMany() throws Exception {
Session s = openSession();
s.getTransaction().begin();
Luggage l = new LuggageImpl();
l.setHeight( 12 );
l.setWidth( 12 );
Size size = new SizeImpl();
size.setName( "S" );
Owner o = new OwnerImpl();
o.setName( "Emmanuel" );
l.setOwner( o );
s.persist( l );
Brand b = new Brand();
s.persist( b );
b.getSizePerLuggage().put( l, size );
s.flush();
s.clear();
b = (Brand) s.get(Brand.class, b.getId() );
assertEquals( 12d, b.getSizePerLuggage().keySet().iterator().next().getWidth() );
s.getTransaction().rollback();
s.close();
}
protected Class[] getMappings() {
return new Class[] {
LuggageImpl.class,
Brand.class
};
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -