<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3720874341343367688</id><updated>2024-08-31T13:56:58.786+02:00</updated><category term="java"/><category term="hibernate"/><category term="maven"/><category term="testing"/><category term="ejb"/><category term="flex"/><category term="glassfish"/><category term="install eclipse linux ubuntu"/><category term="jsf"/><category term="maven appfuse"/><category term="oracle dbunit"/><category term="spring"/><title type='text'>Code-Ref</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://code-ref.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://code-ref.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Tom</name><uri>http://www.blogger.com/profile/16608581073693625135</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3720874341343367688.post-4966091038942013491</id><published>2011-09-08T22:30:00.000+02:00</published><updated>2011-09-08T22:30:00.477+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="flex"/><title type='text'>Flex 3.5 compile error</title><content type='html'>I encountered the following flex compile-time errors (using flex sdk 3.5.x):  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:plain&quot;&gt;1046: Type was not found or was not a compile-time constant: ModelLocator.

1120: Access of undefined property be.
&lt;/pre&gt;&lt;br /&gt;
while trying to compile an ActionScript3 file containing:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:as3&quot;&gt;...
private var model1:be.myPackage1.ModelLocator = 
   be.myPackage1.ModelLocator.getInstance();		
private var model2:be.myPackage2.ModelLocator = 
   be.myPackage2.ModelLocator.getInstance();
...
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
I had to import these classes explicitly in order to make the error go away. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:as3&quot;&gt;...
import be.myPackage1.ModelLocator
import be.myPackage2.ModelLocator
...
&lt;/pre&gt;&lt;br /&gt;
The weird thing is that I copied the variable assignments from a class that does compile, even without the explicit imports. &lt;br /&gt;
&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://code-ref.blogspot.com/feeds/4966091038942013491/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-ref.blogspot.com/2011/09/flex-35-compile-error.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/4966091038942013491'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/4966091038942013491'/><link rel='alternate' type='text/html' href='http://code-ref.blogspot.com/2011/09/flex-35-compile-error.html' title='Flex 3.5 compile error'/><author><name>Tom</name><uri>http://www.blogger.com/profile/16608581073693625135</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3720874341343367688.post-747473470341063245</id><published>2011-08-25T11:01:00.001+02:00</published><updated>2011-08-25T11:02:10.355+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="oracle dbunit"/><title type='text'>DbUnit NoSuchColumnException using Oracle with synonym chain.</title><content type='html'>I stumbled on the is problem using DbUnit 2.4.8 and Oracle driver 11.1.0.6.0 for table names that are actually synonyms pointing to an other synonym pointing to a view in an other schema. (long story...)&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&#39;brush: plain&#39;&gt;WARN [2011-08-24 08:30:40] [user=] (DatabaseTableMetaData.java:getColumns:348) - No columns found for table &#39;XXX_TABLE&#39; that are supported by dbunit. Will return an empty column list

org.dbunit.dataset.NoSuchColumnException: XXX_TABLE.XXX_ID -  (Non-uppercase input column: XXX_ID) in ColumnNameToIndexes cache map. Note that the map&#39;s column names are NOT case sensitive.
	at org.dbunit.dataset.AbstractTableMetaData.getColumnIndex(AbstractTableMetaData.java:117)
	at org.dbunit.operation.AbstractOperation.getOperationMetaData(AbstractOperation.java:89)
	at org.dbunit.operation.AbstractBatchOperation.execute(AbstractBatchOperation.java:140)

&lt;/pre&gt;&lt;br /&gt;
It looks like OracleDatabaseMetaData doesn&#39;t take into account chained synonyms, even with &quot;SYNONYM&quot; included in the dbUnit table types config property (DatabaseConfig.PROPERTY_TABLE_TYPE).&lt;br /&gt;
&lt;br /&gt;
To work around this problem, I extended the DefaultMetadataHandler to resolve the actual schema_name/table_name when needed.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&#39;brush: java&#39;&gt;import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.dbunit.database.DefaultMetadataHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcOperations;

import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * Solves the problem where Dbunit throws a NoSuchColumnException because it cannot resolve the column names through
 * a chain of synonyms.
 */
public class OracleSynonymAwareMetaDataHandler extends DefaultMetadataHandler {

    public static final Logger logger = LoggerFactory.getLogger(OracleSynonymAwareMetaDataHandler.class);

    private final Map&amp;lt;TableInfo, TableInfo&amp;gt; synonymMap;
    private final SimpleJdbcOperations simpleJdbcOperations;

    private static final String SQL_SELECT_USER_SYNONYM =
            &amp;quot;\n with filter1 as (  &amp;quot; +
                    &amp;quot;\n select connect_by_root synonym_name root_synonym_name,  &amp;quot; +
                    &amp;quot;\n 	   connect_by_root table_owner root_table_owner,  &amp;quot; +
                    &amp;quot;\n 	   level lvl,  &amp;quot; +
                    &amp;quot;\n 	   syn.*  &amp;quot; +
                    &amp;quot;\n from user_synonyms syn  &amp;quot; +
                    &amp;quot;\n connect by synonym_name = prior table_name and (table_owner != prior table_owner)  &amp;quot; +
                    &amp;quot;\n start with synonym_name = :p_synonym_name and table_owner = :p_schema_name   &amp;quot; +
                    &amp;quot;\n ), filter2 as (  &amp;quot; +
                    &amp;quot;\n select filter1.*,  &amp;quot; +
                    &amp;quot;\n 	   max(lvl) over (PARTITION BY root_synonym_name, root_table_owner) max_lvl  &amp;quot; +
                    &amp;quot;\n from filter1  &amp;quot; +
                    &amp;quot;\n )  &amp;quot; +
                    &amp;quot;\n select table_owner,  &amp;quot; +
                    &amp;quot;\n 	   table_name  &amp;quot; +
                    &amp;quot;\n from filter2  &amp;quot; +
                    &amp;quot;\n where lvl = max_lvl  &amp;quot;;


    public OracleSynonymAwareMetaDataHandler(SimpleJdbcOperations simpleJdbcOperations) {
        synonymMap = new HashMap&amp;lt;TableInfo, TableInfo&amp;gt;();
        this.simpleJdbcOperations = simpleJdbcOperations;
    }

    @Override
    public ResultSet getColumns(final DatabaseMetaData databaseMetaData,
                                final String schemaName,
                                final String tableName)
            throws SQLException {

        final TableInfo tableInfo = getTableInfo(schemaName, tableName);

        return super.getColumns(databaseMetaData, tableInfo.getSchemaName(), 
                                tableInfo.getTableName());
    }

    @Override
    public boolean matches(ResultSet columnsResultSet,
                           String catalog,
                           String schemaName,
                           String tableName,
                           String column,
                           boolean caseSensitive)
            throws SQLException {

        final TableInfo tableInfo = getTableInfo(schemaName, tableName);

        return super.matches(columnsResultSet, catalog, tableInfo.getSchemaName(), 
                             tableInfo.getTableName(), column, caseSensitive);
    }

    @Override
    public ResultSet getPrimaryKeys(DatabaseMetaData metaData,
                                    String schemaName,
                                    String tableName)
            throws SQLException {

        final TableInfo tableInfo = getTableInfo(schemaName, tableName);

        return super.getPrimaryKeys(metaData, tableInfo.getSchemaName(), 
                                    tableInfo.getTableName());
    }

    /**
     * returns the ACTUAL schemaName and tableName for the provided values
     */
    private TableInfo getTableInfo(final String schemaName, final String tableName) {

        logger.debug(&amp;quot;getTableInfo - schemaName: {}, tableName: {}&amp;quot;, schemaName, tableName);

        TableInfo requestTableInfo = new TableInfo(schemaName, tableName);

        if (synonymMap.containsKey(requestTableInfo)) {
            return synonymMap.get(requestTableInfo);
        } else {
            TableInfo actualTableInfo = (TableInfo) DataAccessUtils.singleResult(
                simpleJdbcOperations.getNamedParameterJdbcOperations().query(
                    SQL_SELECT_USER_SYNONYM,
                    new HashMap&amp;lt;String, Object&amp;gt;() {{
                        put(&amp;quot;p_synonym_name&amp;quot;, tableName);
                        put(&amp;quot;p_schema_name&amp;quot;, schemaName);
                    }},
                    new ParameterizedRowMapper&amp;lt;tableinfo&amp;gt;() {
                        @Override
                        public TableInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
                            int ndx = 0;
                            return new TableInfo(
                                    rs.getString(++ndx)
                                    , rs.getString(++ndx)
                            );
                        }
                    }
            ));

            if (actualTableInfo == null) {
                actualTableInfo = requestTableInfo;
            }

            synonymMap.put(requestTableInfo, actualTableInfo);

            return actualTableInfo;
        }
    }


    private static class TableInfo {
        private final String schemaName;
        private final String tableName;

        private TableInfo(String schemaName, String tableName) {
            this.schemaName = schemaName;
            this.tableName = tableName;
        }

        public String getSchemaName() {
            return schemaName;
        }

        public String getTableName() {
            return tableName;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof TableInfo)) return false;

            TableInfo that = (TableInfo) o;

            return EqualsBuilder.reflectionEquals(this, that);
        }

        @Override
        public int hashCode() {
            return HashCodeBuilder.reflectionHashCode(this);
        }

        @Override
        public String toString() {
            return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
        }
    }
}

&lt;/pre&gt;&lt;br /&gt;
This OracleSynonymAwareMetaDataHandler class can be configured into dbUnit using the DatabaseConfig.PROPERTY_METADATA_HANDLER config property.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;iDatabaseConnection.getConfig()
    .setProperty(DatabaseConfig.PROPERTY_METADATA_HANDLER, 
        oracleSynonymAwareMetaDataHandlerInstance );

&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The hierarchical (oracle) query I wrote is a bit tricky, but it returns the &#39;deepest&#39; synonym on the fly. The same result could be achieved by recursively retrieving a single synonym at a time until no result is found.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: sql&quot;&gt;with filter1 as (
select connect_by_root synonym_name root_synonym_name,
	   connect_by_root table_owner root_table_owner,
	   level lvl,	   	    
	   syn.*	     
from user_synonyms syn
connect by synonym_name = prior table_name and (table_owner != prior table_owner)
start with synonym_name = :p_synonym_name and table_owner = :p_schema_name 
), filter2 as (
select filter1.*,
	   max(lvl) over (PARTITION BY root_synonym_name, root_table_owner) max_lvl
from filter1
)
select table_owner,
	   table_name
from filter2
where lvl = max_lvl
&lt;/pre&gt;&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://code-ref.blogspot.com/feeds/747473470341063245/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-ref.blogspot.com/2011/08/dbunit-nosuchcolumnexception-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/747473470341063245'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/747473470341063245'/><link rel='alternate' type='text/html' href='http://code-ref.blogspot.com/2011/08/dbunit-nosuchcolumnexception-using.html' title='DbUnit NoSuchColumnException using Oracle with synonym chain.'/><author><name>Tom</name><uri>http://www.blogger.com/profile/16608581073693625135</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3720874341343367688.post-2025123607820720883</id><published>2011-08-25T11:00:00.001+02:00</published><updated>2011-08-25T11:00:07.795+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="install eclipse linux ubuntu"/><title type='text'>Installing eclipse 3.7 (indigo) on Ubuntu</title><content type='html'>Installing an alternative eclipse as the one provided through the software center is not that difficult. &lt;br /&gt;
&lt;br /&gt;
Go the the eclipse download page, and download the package that suits you most. I went for the 64 bit JEE version: eclipse-jee-indigo-linux-gtk-x86_64.tar.gz.&lt;br /&gt;
&lt;br /&gt;
Next, open a terminal and execute the folowing commands:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&#39;brush: shell; gutter : true&#39;&gt;tar zxfv eclipse-jee-indigo-linux-gtk-x86_64.tar.gz

mv eclipse eclipse-3.7

sudo mv eclipse-3.7 /opt

cd /opt

sudo chown -R root:root eclipse-3.7

sudo ln -s /opt/eclipse-3.7/eclipse /usr/bin/eclipse
&lt;/pre&gt;&lt;br /&gt;
The same procedure works for other versions as well.</content><link rel='replies' type='application/atom+xml' href='http://code-ref.blogspot.com/feeds/2025123607820720883/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-ref.blogspot.com/2011/08/installing-eclipse-37-indigo-on-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/2025123607820720883'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/2025123607820720883'/><link rel='alternate' type='text/html' href='http://code-ref.blogspot.com/2011/08/installing-eclipse-37-indigo-on-ubuntu.html' title='Installing eclipse 3.7 (indigo) on Ubuntu'/><author><name>Tom</name><uri>http://www.blogger.com/profile/16608581073693625135</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3720874341343367688.post-390915258031655795</id><published>2009-12-14T16:32:00.008+01:00</published><updated>2010-01-04T14:19:42.696+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="maven appfuse"/><title type='text'>Maven archetype-plugin</title><content type='html'>I wanted to try-out Maven 3 and Appfuse 2.1 today. Unfortunatly, I lost some time due to a problem with the Archetype-plugin, and me being behind proxy.&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;brush: plain&quot;&gt;mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-modular-spring-archetype -DarchetypeVersion=2.1.0-M2-SNAPSHOT -DgroupId=be.fatsu -DartifactId=test1 -DarchetypeRepository=http://oss.sonatype.org/content/repositories/appfuse&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;as generated by the appfuse quickstart page fails with TransferFailedException: Error transferring file.&lt;br /&gt;&lt;br /&gt;The Archetype plugin apparently doesn&#39;t take into account the proxy configuration from the maven settings, as explained in the related issue: &lt;a href=&quot;http://jira.codehaus.org/browse/ARCHETYPE-202&quot;&gt;ARCHETYPE-202&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The easiest way around this is by setting system variables:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;brush: plain&quot;&gt;mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-modular-spring-archetype -DarchetypeVersion=2.1.0-M2-SNAPSHOT -DgroupId=be.fatsu -DartifactId=test1 -DarchetypeRepository=http://oss.sonatype.org/content/repositories/appfuse -Dhttp.proxyHost=xxx.xxx.xxx.xxx -Dhttp.proxyPort=xxxx -Dhttp.proxyUser=xxxxxxx -Dhttp.proxyPassword=xxxxxxx&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-ref.blogspot.com/feeds/390915258031655795/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-ref.blogspot.com/2009/12/maven-archetype-plugin.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/390915258031655795'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/390915258031655795'/><link rel='alternate' type='text/html' href='http://code-ref.blogspot.com/2009/12/maven-archetype-plugin.html' title='Maven archetype-plugin'/><author><name>Tom</name><uri>http://www.blogger.com/profile/16608581073693625135</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3720874341343367688.post-8601421734605791006</id><published>2009-06-26T13:33:00.006+02:00</published><updated>2009-12-14T15:47:22.448+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="maven"/><category scheme="http://www.blogger.com/atom/ns#" term="testing"/><title type='text'>Specific Cobertura version in Maven-cobertura-plugin</title><content type='html'>I found this &lt;a href=&quot;http://www.sonatype.com/people/2008/04/how-to-override-a-plugins-dependency-in-maven/&quot;&gt;blog post&lt;/a&gt; by Brian Fox explaining how to override a plugin&#39;s dependencies. &lt;br /&gt;This allowed me to configure the maven-cobertura-plugin to use a specific cobertura version (1.9.1.1 being the latest one available in the central maven repository), instead of the one configured by the plugin itself (1.9). &lt;br /&gt;As stated by Brian, as long as the newly introduced version&#39;s API is compatible with the original one, there should be no problem.&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt; &amp;lt;build&amp;gt;&lt;br /&gt;  &amp;lt;plugins&amp;gt;&lt;br /&gt;   &amp;lt;plugin&amp;gt;&lt;br /&gt;    &amp;lt;groupId&amp;gt;org.codehaus.mojo&amp;lt;/groupId&amp;gt;&lt;br /&gt;    &amp;lt;artifactId&amp;gt;cobertura-maven-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;    &amp;lt;dependencies&amp;gt;&lt;br /&gt;     &amp;lt;dependency&amp;gt;&lt;br /&gt;      &amp;lt;groupId&amp;gt;net.sourceforge.cobertura&amp;lt;/groupId&amp;gt;&lt;br /&gt;      &amp;lt;artifactId&amp;gt;cobertura&amp;lt;/artifactId&amp;gt;&lt;br /&gt;      &amp;lt;version&amp;gt;1.9.1.1&amp;lt;/version&amp;gt;&lt;br /&gt;     &amp;lt;/dependency&amp;gt;&lt;br /&gt;    &amp;lt;/dependencies&amp;gt;&lt;br /&gt;   &amp;lt;/plugin&amp;gt;&lt;br /&gt;  &amp;lt;/plugins&amp;gt;&lt;br /&gt; &amp;lt;/build&amp;gt;&lt;br /&gt; &amp;lt;reporting&amp;gt;&lt;br /&gt;  &amp;lt;plugins&amp;gt;&lt;br /&gt;   &amp;lt;plugin&amp;gt;&lt;br /&gt;    &amp;lt;groupId&amp;gt;org.codehaus.mojo&amp;lt;/groupId&amp;gt;&lt;br /&gt;    &amp;lt;artifactId&amp;gt;cobertura-maven-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;   &amp;lt;/plugin&amp;gt;&lt;br /&gt;  &amp;lt;/plugins&amp;gt;&lt;br /&gt; &amp;lt;/reporting&amp;gt;&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-ref.blogspot.com/feeds/8601421734605791006/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-ref.blogspot.com/2009/06/specific-cobertura-version-in-maven.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/8601421734605791006'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/8601421734605791006'/><link rel='alternate' type='text/html' href='http://code-ref.blogspot.com/2009/06/specific-cobertura-version-in-maven.html' title='Specific Cobertura version in Maven-cobertura-plugin'/><author><name>Tom</name><uri>http://www.blogger.com/profile/16608581073693625135</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3720874341343367688.post-1416567868958303772</id><published>2009-06-24T15:06:00.005+02:00</published><updated>2009-12-14T15:45:14.730+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="maven"/><category scheme="http://www.blogger.com/atom/ns#" term="spring"/><category scheme="http://www.blogger.com/atom/ns#" term="testing"/><title type='text'>Maven: Spring-Test 2.5.x &amp; JUnit 4</title><content type='html'>I ran into this weird problem today while setting up an integration-testing module in my maven project: The Surefire-plugin seemed to ignore the JUnit4 annotations.&lt;br /&gt;I found a Maven-Surefire issue (&lt;a href=&quot;http://jira.codehaus.org/browse/SUREFIRE-448&quot;&gt;SUREFIRE-448&lt;/a&gt;) describing the same problem, but it is marked as irreproducible and proposes no solution.&lt;br /&gt;After looking into the debug information (mvn clean test -X &gt; log.txt), it turns out that Spring-Test has a dependency on JUnit 3.8.1, and this is causing my test classes to run as JUnit3 instead of JUnit4.&lt;br /&gt;To fix this, simply exclude JUnit from the Spring-Test dependency: &lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;&amp;lt;dependency&amp;gt;&lt;br /&gt;   &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;&lt;br /&gt;   &amp;lt;artifactId&amp;gt;spring-test&amp;lt;/artifactId&amp;gt;&lt;br /&gt;   &amp;lt;version&amp;gt;2.5.6&amp;lt;/version&amp;gt;&lt;br /&gt;   &amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt;&lt;br /&gt;   &amp;lt;exclusions&amp;gt;&lt;br /&gt;    &amp;lt;exclusion&amp;gt;&lt;br /&gt;     &amp;lt;groupId&amp;gt;junit&amp;lt;/groupId&amp;gt;&lt;br /&gt;     &amp;lt;artifactId&amp;gt;junit&amp;lt;/artifactId&amp;gt;&lt;br /&gt;    &amp;lt;/exclusion&amp;gt;&lt;br /&gt;   &amp;lt;/exclusions&amp;gt;&lt;br /&gt;&amp;lt;/dependency&amp;gt;&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-ref.blogspot.com/feeds/1416567868958303772/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-ref.blogspot.com/2009/06/maven-spring-test-25x-junit-4.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/1416567868958303772'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/1416567868958303772'/><link rel='alternate' type='text/html' href='http://code-ref.blogspot.com/2009/06/maven-spring-test-25x-junit-4.html' title='Maven: Spring-Test 2.5.x &amp; JUnit 4'/><author><name>Tom</name><uri>http://www.blogger.com/profile/16608581073693625135</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3720874341343367688.post-3209135371822243687</id><published>2009-06-18T15:22:00.010+02:00</published><updated>2009-12-14T15:44:23.865+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>initializing static final Collection/Map in one statement</title><content type='html'>Initializing a static final (unmodifiable) Map:&lt;br /&gt;&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;private final static Map&amp;lt;String,String&amp;gt; map = Collections.unmodifiableMap(new HashMap&amp;lt;String,String&amp;gt;() {&lt;br /&gt; {&lt;br /&gt;  put(&amp;quot;key1&amp;quot;, &amp;quot;value1&amp;quot;);&lt;br /&gt;  put(&amp;quot;key2&amp;quot;, &amp;quot;value2&amp;quot;);&lt;br /&gt; }&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Initializing a static final (unmodifiable) Collection:&lt;br /&gt;&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;private final static Set&amp;lt;String&amp;gt; set = Collections.unmodifiableSet(new HashSet&amp;lt;String&amp;gt;() {&lt;br /&gt;  {&lt;br /&gt;   add(&amp;quot;value1&amp;quot;);&lt;br /&gt;   add(&amp;quot;value2&amp;quot;);&lt;br /&gt;  }&lt;br /&gt; });&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-ref.blogspot.com/feeds/3209135371822243687/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-ref.blogspot.com/2009/06/initializing-static-final-collectionmap.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/3209135371822243687'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/3209135371822243687'/><link rel='alternate' type='text/html' href='http://code-ref.blogspot.com/2009/06/initializing-static-final-collectionmap.html' title='initializing static final Collection/Map in one statement'/><author><name>Tom</name><uri>http://www.blogger.com/profile/16608581073693625135</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3720874341343367688.post-5358128975889847364</id><published>2009-06-15T10:40:00.011+02:00</published><updated>2009-12-14T15:43:42.690+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="hibernate"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>Hibernate GenericEnumUserType</title><content type='html'>Hibernate usertype for getting/setting a custom value instead of using @Enumerated(EnumType.STRING) or @Enumerated(EnumType.Ordinal)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;UserType source:&lt;br /&gt;&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;package example.usertype;&lt;br /&gt;&lt;br /&gt;import java.io.Serializable;&lt;br /&gt;import java.lang.reflect.Method;&lt;br /&gt;import java.sql.PreparedStatement;&lt;br /&gt;import java.sql.ResultSet;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt;import java.util.Properties;&lt;br /&gt;&lt;br /&gt;import org.hibernate.HibernateException;&lt;br /&gt;import org.hibernate.type.NullableType;&lt;br /&gt;import org.hibernate.type.TypeFactory;&lt;br /&gt;import org.hibernate.usertype.ParameterizedType;&lt;br /&gt;import org.hibernate.usertype.UserType;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * generic enum user type based on: http://www.hibernate.org/272.html&lt;br /&gt; * &lt;br /&gt; * @param enumClass&lt;br /&gt; * @param identifierMethod&lt;br /&gt; * @param valueOfMethod&lt;br /&gt; */&lt;br /&gt;public class GenericEnumUserType implements UserType, ParameterizedType {&lt;br /&gt; private static final String DEFAULT_IDENTIFIER_METHOD_NAME = &amp;quot;name&amp;quot;;&lt;br /&gt; private static final String DEFAULT_VALUE_OF_METHOD_NAME = &amp;quot;valueOf&amp;quot;;&lt;br /&gt;&lt;br /&gt; @SuppressWarnings(&amp;quot;unchecked&amp;quot;)&lt;br /&gt; private Class&amp;lt;? extends Enum&amp;gt; enumClass;&lt;br /&gt; private Class&amp;lt;?&amp;gt; identifierType;&lt;br /&gt; private Method identifierMethod;&lt;br /&gt; private Method valueOfMethod;&lt;br /&gt; private NullableType type;&lt;br /&gt; private int[] sqlTypes;&lt;br /&gt;&lt;br /&gt; public void setParameterValues(Properties parameters) {&lt;br /&gt;  String enumClassName = parameters.getProperty(&amp;quot;enumClass&amp;quot;);&lt;br /&gt;  try {&lt;br /&gt;   enumClass = Class.forName(enumClassName).asSubclass(Enum.class);&lt;br /&gt;  } catch (ClassNotFoundException cfne) {&lt;br /&gt;   throw new HibernateException(&amp;quot;Enum class not found&amp;quot;, cfne);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  String identifierMethodName = parameters.getProperty(&lt;br /&gt;    &amp;quot;identifierMethod&amp;quot;, DEFAULT_IDENTIFIER_METHOD_NAME);&lt;br /&gt;&lt;br /&gt;  try {&lt;br /&gt;   identifierMethod = enumClass.getMethod(identifierMethodName,&lt;br /&gt;     new Class[0]);&lt;br /&gt;   identifierType = identifierMethod.getReturnType();&lt;br /&gt;  } catch (Exception e) {&lt;br /&gt;   throw new HibernateException(&amp;quot;Failed to obtain identifier method&amp;quot;,&lt;br /&gt;     e);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  type = (NullableType) TypeFactory.basic(identifierType.getName());&lt;br /&gt;&lt;br /&gt;  if (type == null)&lt;br /&gt;   throw new HibernateException(&amp;quot;Unsupported identifier type &amp;quot;&lt;br /&gt;     + identifierType.getName());&lt;br /&gt;&lt;br /&gt;  sqlTypes = new int[] { type.sqlType() };&lt;br /&gt;&lt;br /&gt;  String valueOfMethodName = parameters.getProperty(&amp;quot;valueOfMethod&amp;quot;,&lt;br /&gt;    DEFAULT_VALUE_OF_METHOD_NAME);&lt;br /&gt;&lt;br /&gt;  try {&lt;br /&gt;   valueOfMethod = enumClass.getMethod(valueOfMethodName,&lt;br /&gt;     new Class[] { identifierType });&lt;br /&gt;  } catch (Exception e) {&lt;br /&gt;   throw new HibernateException(&amp;quot;Failed to obtain valueOf method&amp;quot;, e);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; @SuppressWarnings(&amp;quot;unchecked&amp;quot;)&lt;br /&gt; public Class returnedClass() {&lt;br /&gt;  return enumClass;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public Object nullSafeGet(ResultSet rs, String[] names, Object owner)&lt;br /&gt;   throws HibernateException, SQLException {&lt;br /&gt;  Object identifier = type.get(rs, names[0]);&lt;br /&gt;  if (identifier == null) {&lt;br /&gt;   return null;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  // fix for fixed length char datatype (db2)&lt;br /&gt;  if (identifier instanceof String) {&lt;br /&gt;   identifier = ((String) identifier).trim();&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  Object value;&lt;br /&gt;  try {&lt;br /&gt;   value = valueOfMethod&lt;br /&gt;     .invoke(enumClass, new Object[] { identifier });&lt;br /&gt;  } catch (Exception e) {&lt;br /&gt;   throw new HibernateException(&lt;br /&gt;     &amp;quot;Exception while invoking valueOf method &#39;&amp;quot;&lt;br /&gt;       + valueOfMethod.getName() + &amp;quot;&#39; of &amp;quot;&lt;br /&gt;       + &amp;quot;enumeration class &#39;&amp;quot; + enumClass + &amp;quot;&#39;&amp;quot;, e);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  if (value == null) {&lt;br /&gt;   throw new HibernateException(&lt;br /&gt;     &amp;quot;Impossible to translate identifier-value &#39;&amp;quot; + identifier&lt;br /&gt;       + &amp;quot;&#39; to enum of type &#39;&amp;quot; + enumClass + &amp;quot;&#39;&amp;quot;);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  return value;&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void nullSafeSet(PreparedStatement st, Object value, int index)&lt;br /&gt;   throws HibernateException, SQLException {&lt;br /&gt;&lt;br /&gt;  if (value == null) {&lt;br /&gt;   st.setNull(index, type.sqlType());&lt;br /&gt;  } else {&lt;br /&gt;   Object identifier;&lt;br /&gt;   try {&lt;br /&gt;    identifier = identifierMethod.invoke(value, new Object[0]);&lt;br /&gt;   } catch (Exception e) {&lt;br /&gt;    throw new HibernateException(&lt;br /&gt;      &amp;quot;Exception while invoking identifierMethod &#39;&amp;quot;&lt;br /&gt;        + identifierMethod.getName() + &amp;quot;&#39; of &amp;quot;&lt;br /&gt;        + &amp;quot;enumeration class &#39;&amp;quot; + enumClass + &amp;quot;&#39;&amp;quot;, e);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   if (identifier == null) {&lt;br /&gt;    throw new HibernateException(&lt;br /&gt;      &amp;quot;Disallowed to update/insert null identifier-value for non-null enum-value of type &#39;&amp;quot;&lt;br /&gt;        + enumClass + &amp;quot;&#39;&amp;quot;);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   type.set(st, identifier, index);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public int[] sqlTypes() {&lt;br /&gt;  return sqlTypes;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public Object assemble(Serializable cached, Object owner)&lt;br /&gt;   throws HibernateException {&lt;br /&gt;  return cached;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public Object deepCopy(Object value) throws HibernateException {&lt;br /&gt;  return value;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public Serializable disassemble(Object value) throws HibernateException {&lt;br /&gt;  return (Serializable) value;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public boolean equals(Object x, Object y) throws HibernateException {&lt;br /&gt;  return x == y;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public int hashCode(Object x) throws HibernateException {&lt;br /&gt;  return x.hashCode();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public boolean isMutable() {&lt;br /&gt;  return false;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public Object replace(Object original, Object target, Object owner)&lt;br /&gt;   throws HibernateException {&lt;br /&gt;  return original;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Enum source:&lt;br /&gt;&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;package example.model;&lt;br /&gt;&lt;br /&gt;import java.util.EnumSet;&lt;br /&gt;import java.util.HashMap;&lt;br /&gt;import java.util.Map;&lt;br /&gt;&lt;br /&gt;public enum Direction {&lt;br /&gt;&lt;br /&gt; INCOMING(&#39;I&#39;), //&lt;br /&gt; OUTGOING(&#39;O&#39;); //&lt;br /&gt;&lt;br /&gt; private static final Map&amp;lt;Character, Direction&amp;gt; idMap = new HashMap&amp;lt;Character, Direction&amp;gt;();&lt;br /&gt; &lt;br /&gt; static {&lt;br /&gt;  for (Direction direction : EnumSet.allOf(Direction.class)) {&lt;br /&gt;   idMap.put(direction.getId(), direction);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private final Character id;&lt;br /&gt;&lt;br /&gt; private Direction(Character id) {&lt;br /&gt;  this.id = id;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public static Direction valueById(Character id) {&lt;br /&gt;  return idMap.get(id);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public Character getId() {&lt;br /&gt;  return id;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Usage:&lt;br /&gt;&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;@Type(type = &amp;quot;example.usertype.GenericEnumUserType&amp;quot;, parameters = {&lt;br /&gt;   @Parameter(name = &amp;quot;enumClass&amp;quot;, value = &amp;quot;example.model.Direction&amp;quot;),&lt;br /&gt;   @Parameter(name = &amp;quot;identifierMethod&amp;quot;, value = &amp;quot;getId&amp;quot;),&lt;br /&gt;   @Parameter(name = &amp;quot;valueOfMethod&amp;quot;, value = &amp;quot;valueById&amp;quot;) })&lt;br /&gt; @Column(name = &amp;quot;DIRECTION&amp;quot;, nullable = false, length = 1)&lt;br /&gt; public Direction getDirection() {&lt;br /&gt;  return this.direction;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void setDirection(Direction direction) {&lt;br /&gt;  this.direction = direction;&lt;br /&gt; }&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-ref.blogspot.com/feeds/5358128975889847364/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-ref.blogspot.com/2009/06/hibernate-genericenumusertype.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/5358128975889847364'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/5358128975889847364'/><link rel='alternate' type='text/html' href='http://code-ref.blogspot.com/2009/06/hibernate-genericenumusertype.html' title='Hibernate GenericEnumUserType'/><author><name>Tom</name><uri>http://www.blogger.com/profile/16608581073693625135</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3720874341343367688.post-6903788380595355301</id><published>2009-06-15T10:36:00.008+02:00</published><updated>2009-12-14T15:42:35.581+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="hibernate"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>Hibernate StringTrimUserType</title><content type='html'>Use for fixed length column definitions. (e.g. DB2 &#39;char&#39; type)&lt;br /&gt;&lt;br /&gt;Source:&lt;br /&gt;&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;package example.usertype;&lt;br /&gt;&lt;br /&gt;import java.io.Serializable;&lt;br /&gt;import java.sql.PreparedStatement;&lt;br /&gt;import java.sql.ResultSet;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt;import java.sql.Types;&lt;br /&gt;&lt;br /&gt;import org.hibernate.Hibernate;&lt;br /&gt;import org.hibernate.usertype.UserType;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * &lt;br /&gt; * based on www.hibernate.org/388.html&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;public class StringTrimUserType implements UserType {&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * &lt;br /&gt;  * default constructor&lt;br /&gt;  */&lt;br /&gt;&lt;br /&gt; public StringTrimUserType() {&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * &lt;br /&gt;  * @see org.hibernate.usertype.UserType#sqlTypes()&lt;br /&gt;  */&lt;br /&gt;&lt;br /&gt; public int[] sqlTypes() {&lt;br /&gt;  return new int[] { Types.CHAR };&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * &lt;br /&gt;  * @see org.hibernate.usertype.UserType#returnedClass()&lt;br /&gt;  */&lt;br /&gt;&lt;br /&gt; @SuppressWarnings(&amp;quot;unchecked&amp;quot;)&lt;br /&gt; public Class returnedClass() {&lt;br /&gt;  return String.class;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * &lt;br /&gt;  * @see org.hibernate.usertype.UserType#equals(java.lang.Object,&lt;br /&gt;  *      java.lang.Object)&lt;br /&gt;  */&lt;br /&gt;&lt;br /&gt; public boolean equals(Object x, Object y) {&lt;br /&gt;  return (x == y) || (x != null &amp;&amp; y != null &amp;&amp; (x.equals(y)));&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * &lt;br /&gt;  * @see org.hibernate.usertype.UserType#nullSafeGet(java.sql.ResultSet,&lt;br /&gt;  *      java.lang.String[], java.lang.Object)&lt;br /&gt;  */&lt;br /&gt;&lt;br /&gt; public Object nullSafeGet(ResultSet inResultSet, String[] names, Object o) throws SQLException {&lt;br /&gt;&lt;br /&gt;  String val = (String) Hibernate.STRING.nullSafeGet(inResultSet, names[0]);&lt;br /&gt;  return val == null ? null : val.trim();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * &lt;br /&gt;  * @see org.hibernate.usertype.UserType#nullSafeSet(java.sql.PreparedStatement,&lt;br /&gt;  *      java.lang.Object, int)&lt;br /&gt;  */&lt;br /&gt;&lt;br /&gt; public void nullSafeSet(PreparedStatement inPreparedStatement, Object o,&lt;br /&gt;   int i)&lt;br /&gt;&lt;br /&gt; throws SQLException {&lt;br /&gt;&lt;br /&gt;  String val = (String) o;&lt;br /&gt;  inPreparedStatement.setString(i, val);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * &lt;br /&gt;  * @see org.hibernate.usertype.UserType#deepCopy(java.lang.Object)&lt;br /&gt;  */&lt;br /&gt;&lt;br /&gt; public Object deepCopy(Object o) {&lt;br /&gt;  if (o == null) {&lt;br /&gt;   return null;&lt;br /&gt;  }&lt;br /&gt;  return new String(((String) o));&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * &lt;br /&gt;  * @see org.hibernate.usertype.UserType#isMutable()&lt;br /&gt;  */&lt;br /&gt;&lt;br /&gt; public boolean isMutable() {&lt;br /&gt;  return false;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * &lt;br /&gt;  * @see org.hibernate.usertype.UserType#assemble(java.io.Serializable,&lt;br /&gt;  *      java.lang.Object)&lt;br /&gt;  */&lt;br /&gt;&lt;br /&gt; public Object assemble(Serializable cached, Object owner) {&lt;br /&gt;  return cached;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * &lt;br /&gt;  * @see org.hibernate.usertype.UserType#disassemble(java.lang.Object)&lt;br /&gt;  */&lt;br /&gt;&lt;br /&gt; public Serializable disassemble(Object value) {&lt;br /&gt;  return (Serializable) value;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * &lt;br /&gt;  * @see org.hibernate.usertype.UserType#replace(java.lang.Object,&lt;br /&gt;  *      java.lang.Object, java.lang.Object)&lt;br /&gt;  */&lt;br /&gt;&lt;br /&gt; public Object replace(Object original, Object target, Object owner) {&lt;br /&gt;  return original;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * &lt;br /&gt;  * @see org.hibernate.usertype.UserType#hashCode(java.lang.Object)&lt;br /&gt;  */&lt;br /&gt;&lt;br /&gt; public int hashCode(Object x) {&lt;br /&gt;  return x.hashCode();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Usage:&lt;br /&gt;&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;@Column(name = &amp;quot;CMODULE&amp;quot;, unique = true, nullable = false, length = 10, columnDefinition = &amp;quot;char&amp;quot;)&lt;br /&gt;    @Type(type = &amp;quot;example.usertype.StringTrimUserType&amp;quot;)&lt;br /&gt;    public String getModuleCode() {&lt;br /&gt; return this.moduleCode;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setModuleCode(String moduleId) {&lt;br /&gt; this.moduleCode = moduleId;&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-ref.blogspot.com/feeds/6903788380595355301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-ref.blogspot.com/2009/06/hibernate-stringtrimusertype.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/6903788380595355301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/6903788380595355301'/><link rel='alternate' type='text/html' href='http://code-ref.blogspot.com/2009/06/hibernate-stringtrimusertype.html' title='Hibernate StringTrimUserType'/><author><name>Tom</name><uri>http://www.blogger.com/profile/16608581073693625135</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3720874341343367688.post-370125630302743921</id><published>2009-03-12T08:49:00.020+01:00</published><updated>2009-12-14T15:41:12.435+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ejb"/><category scheme="http://www.blogger.com/atom/ns#" term="glassfish"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="jsf"/><title type='text'>@EJB injection in JSF managed beans on glassfish with myfaces</title><content type='html'>I was trying to get @EJB dependency to work on my JSF managed beans. MyFaces Tomahawk on a Glassfish v2 app server. I kept getting NullPointerExceptions because the injection didn&#39;t happen... &lt;br /&gt;&lt;br /&gt;Turns out it was failing to inject the ejb implementations because my webapp was trying to use the MyFaces jsf implementation next to the sun RI implementation shipped with Glassfish.&lt;br /&gt;&lt;br /&gt;So, make sure not both the RI implementation (provided by glassfish), and myFaces implementation are active!&lt;br /&gt;&lt;br /&gt;I prevented the myFaces implementation from loading by commenting the StartupServletContextListener in WEB-INF/web.xml (2.5 headers):&lt;/p&gt;&lt;br /&gt;&lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: xml&quot;&gt;&lt;![CDATA[&lt;br /&gt;&lt;!--&lt;br /&gt;&lt;listener&gt;&lt;br /&gt;&lt;listener-class&gt;&lt;br /&gt;org.apache.myfaces.webapp.StartupServletContextListener&lt;br /&gt;&lt;/listener-class&gt;&lt;br /&gt;&lt;/listener&gt;&lt;br /&gt;--&gt;&lt;br /&gt;]]&gt;&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-ref.blogspot.com/feeds/370125630302743921/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-ref.blogspot.com/2009/03/ejb-injection-in-jsf-managed-beans-on.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/370125630302743921'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3720874341343367688/posts/default/370125630302743921'/><link rel='alternate' type='text/html' href='http://code-ref.blogspot.com/2009/03/ejb-injection-in-jsf-managed-beans-on.html' title='@EJB injection in JSF managed beans on glassfish with myfaces'/><author><name>Tom</name><uri>http://www.blogger.com/profile/16608581073693625135</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>