alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (NullablePrimaryKeyTest.java)

This example Hibernate source code file (NullablePrimaryKeyTest.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

annotationconfiguration, annotationconfiguration, exception, logger, nullableprimarykeytest, serviceregistry, sql, sql, sqlserverdialect, sqlserverdialect, string, string, testcase, wrong

The Hibernate NullablePrimaryKeyTest.java source code

//$Id: A320.java 14736 2008-06-04 14:23:42Z hardy.ferentschik $
package org.hibernate.test.annotations.onetoone.primarykey;

import org.jboss.logging.Logger;

import junit.framework.TestCase;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;

/**
 * Test harness for ANN-742.
 *
 * @author Hardy Ferentschik
 *
 */
public class NullablePrimaryKeyTest extends TestCase {
	private static final Logger log = Logger.getLogger( NullablePrimaryKeyTest.class );

	public void testGeneratedSql() {

		ServiceRegistry serviceRegistry = null;
		try {
			AnnotationConfiguration config = new AnnotationConfiguration();
			config.addAnnotatedClass(Address.class);
			config.addAnnotatedClass(Person.class);
			serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
			config.buildSessionFactory( serviceRegistry );
			String[] schema = config
					.generateSchemaCreationScript(new SQLServerDialect());
			for (String s : schema) {
                log.debug(s);
			}
			String expectedMappingTableSql = "create table personAddress (address_id numeric(19,0) null, " +
					"person_id numeric(19,0) not null, primary key (person_id))";
			assertEquals("Wrong SQL", expectedMappingTableSql, schema[2]);
		} catch (Exception e) {
			fail(e.getMessage());
		}
		finally {
			if ( serviceRegistry != null ) {
				ServiceRegistryBuilder.destroy( serviceRegistry );
			}
		}
	}
}

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate NullablePrimaryKeyTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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.