Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.annotations;

import java.io.Serializable;
import java.util.Collection;
import java.util.SortedSet;
Expand Down Expand Up @@ -31,7 +32,7 @@ public class Customer implements Serializable {
Long id;
String name;
SortedSet<Ticket> tickets;
Collection discountTickets;
Collection<Discount> discountTickets;
Passport passport;

public Customer() {
Expand Down Expand Up @@ -69,11 +70,11 @@ public void setTickets(SortedSet<Ticket> tickets) {
@OneToMany(targetEntity = Discount.class,
cascade = CascadeType.ALL, mappedBy = "owner")
@Cascade({ALL})
public Collection getDiscountTickets() {
public Collection<Discount> getDiscountTickets() {
return discountTickets;
}

public void setDiscountTickets(Collection collection) {
public void setDiscountTickets(Collection<Discount> collection) {
discountTickets = collection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.annotations;

import java.io.Serializable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.annotations;

import java.io.Serializable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.annotations;

import java.io.Serializable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down Expand Up @@ -43,13 +44,9 @@ public void setNumber(String string) {

public boolean equals(Object o) {
if ( this == o ) return true;
if ( !( o instanceof Ticket ) ) return false;

final Ticket ticket = (Ticket) o;

if ( !number.equals( ticket.number ) ) return false;
if ( !(o instanceof Ticket ticket) ) return false;

return true;
return number.equals( ticket.number );
}

public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.orm.junit.BaseUnitTest;
import org.junit.jupiter.api.Test;

import org.junit.Assert;
import org.junit.Test;
import static org.assertj.core.api.Fail.fail;

/**
* @author Emmanuel Bernard
*/
@BaseUnitTest
public class ConfigurationTest {
@Test
public void testMixPackageAndResourceOrdering() throws Exception {
public void testMixPackageAndResourceOrdering() {
try (BootstrapServiceRegistry serviceRegistry = new BootstrapServiceRegistryBuilder().build()) {
Configuration config = new Configuration( serviceRegistry );
config.addResource( "org/hibernate/orm/test/annotations/configuration/orm.xml" );
config.addPackage( "org.hibernate.orm/test.annotations.configuration" );
}
catch( Exception e ) {
Assert.fail( "Processing package first when ORM.xml is used should not fail" );
fail( "Processing package first when ORM.xml is used should not fail" );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,83 @@
*/
package org.hibernate.orm.test.annotations.derivedidentities.e1.b;

import org.hibernate.Session;

import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.orm.test.util.SchemaUtil;
import org.junit.Test;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

/**
* @author Emmanuel Bernard
*/
public class DerivedIdentitySimpleParentEmbeddedIdDepTest extends BaseNonConfigCoreFunctionalTestCase {
@Test
public void testManyToOne() throws Exception {
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_empId", metadata() ) );
assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "empPK", metadata() ) );

Employee e = new Employee();
e.empId = 1;
e.empName = "Emmanuel";
Session s = openSession( );
s.getTransaction().begin();
@SessionFactory
@DomainModel(
annotatedClasses = {
Dependent.class,
Employee.class,
ExclusiveDependent.class
}
)
public class DerivedIdentitySimpleParentEmbeddedIdDepTest {

Dependent d = new Dependent();
d.emp = e;
d.id = new DependentId();
d.id.name = "Doggy";
s.persist( d );
s.persist( e );
s.flush();
s.clear();
d = (Dependent) s.get( Dependent.class, d.id );
assertEquals( d.id.empPK, d.emp.empId );
s.getTransaction().rollback();
s.close();
@AfterEach
public void tearDown(SessionFactoryScope scope) {
scope.getSessionFactory().getSchemaManager().truncateMappedObjects();
}

@Test
public void testOneToOne() throws Exception {
assertTrue( SchemaUtil.isColumnPresent( "ExclusiveDependent", "FK", metadata() ) );
assertTrue( ! SchemaUtil.isColumnPresent( "ExclusiveDependent", "empPK", metadata() ) );
public void testManyToOne(SessionFactoryScope scope) {
MetadataImplementor metadata = scope.getMetadataImplementor();
assertThat( SchemaUtil.isColumnPresent( "Dependent", "emp_empId", metadata ) ).isTrue();
assertThat( !SchemaUtil.isColumnPresent( "Dependent", "empPK", metadata ) ).isTrue();

Employee e = new Employee();
e.empId = 1;
e.empName = "Emmanuel";
Session s = openSession( );
s.getTransaction().begin();
s.persist( e );
ExclusiveDependent d = new ExclusiveDependent();
d.emp = e;
d.id = new DependentId();
d.id.name = "Doggy";
//d.id.empPK = e.empId; //FIXME not needed when foreign is enabled
s.persist( d );
s.flush();
s.clear();
d = (ExclusiveDependent) s.get( ExclusiveDependent.class, d.id );
assertEquals( d.id.empPK, d.emp.empId );
s.getTransaction().rollback();
s.close();
scope.inTransaction(
session -> {
Employee e = new Employee();
e.empId = 1;
e.empName = "Emmanuel";
Dependent d = new Dependent();
d.emp = e;
d.id = new DependentId();
d.id.name = "Doggy";
session.persist( d );
session.persist( e );
session.flush();
session.clear();
d = session.find( Dependent.class, d.id );
assertThat( d.emp.empId ).isEqualTo( d.id.empPK );
}
);
}

@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Dependent.class,
Employee.class,
ExclusiveDependent.class
};
@Test
public void testOneToOne(SessionFactoryScope scope) {
MetadataImplementor metadata = scope.getMetadataImplementor();
assertThat( SchemaUtil.isColumnPresent( "ExclusiveDependent", "FK", metadata ) ).isTrue();
assertThat( !SchemaUtil.isColumnPresent( "ExclusiveDependent", "empPK", metadata ) ).isTrue();

scope.inTransaction(
session -> {
Employee e = new Employee();
e.empId = 1;
e.empName = "Emmanuel";
session.persist( e );
ExclusiveDependent d = new ExclusiveDependent();
d.emp = e;
d.id = new DependentId();
d.id.name = "Doggy";
//d.id.empPK = e.empId; //FIXME not needed when foreign is enabled
session.persist( d );
session.flush();
session.clear();
d = session.find( ExclusiveDependent.class, d.id );
assertThat( d.emp.empId ).isEqualTo( d.id.empPK );
}
);
}

}
Loading
Loading