Thursday, June 10, 2010

jQuery calendar IE 7



I was trying to use the jQuery calendar datepicker (http://docs.jquery.com/UI/Datepicker) and I've had it working before on another project (on all browsers including IE 7), but in the current project I'm working on, sometimes the arrows (Next, prev) to move to the next and previous month don't work correctly in IE7. In firefox, opera, safari, IE8 it works fine. What's worse, it also worked fine in IE 7 on the previous project. So how was this project different?

I had noticed that the global CSS property position was set to relative as follows:

* {
    position: relative;
}

 To get it working, I did an override on the global property as follows:
* {
    position: static;
}

That got the arrows in the calendars working again

Monday, June 7, 2010

HibernateException "The class has no identifier property"

I got the above error when updating an existing record loaded from the database and not when inserting new records.

The hbm.xml file showed the following:


        <id column="user_id" type="java.lang.Long">
            <generator class="foreign">
                <param name="property">user</param>
            </generator>
        </id>

I added the name attribute in the id element, and that resolved the issue:


        <id name="id" column="user_id" type="java.lang.Long">
            <generator class="foreign">
                <param name="property">user</param>
            </generator>
        </id>

Wednesday, May 5, 2010

Solr Highlighting

I have used Lucene a few years ago when highlighting was not even feature. Now I am using Solr to perform my searches and highlighting is very much something we would like to use. At first, it was not very clear how to get it working and nor are the docs very helpful. So I've written up a short blurb on what was needed.

If you've configured your schema correctly where the fields to be highlighted must have "stored=true", then most of the work is in your constructed query. You need to add the following to your query:

  • hl=true
  • hl.fl=*
Here is an example query:

http://localhost:8989/solr/select?q=britta&hl=true&hl.fl=*

And an example response might be:

<response>
−
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">8</int>
−
<lst name="params">
<str name="q">britta</str>
<str name="hl.fl">*</str>
<str name="hl">true</str>
</lst>
</lst>
−
<result name="response" numFound="1" start="0">
−
<doc>
<str name="description">britta is awesome</str>
<str name="id">poddObject:67</str>
</doc>
</result>
−
<lst name="highlighting">
−
<lst name="poddObject:67">
−
<arr name="description">
<str><em>britta</em> is awesome</str>
</arr>
</lst>
</lst>
</response>


If it's still not working for you, here is another reference that provides additional things you should look for:
http://www.mail-archive.com/solr-user@lucene.apache.org/msg11031.html

Phil

Tuesday, May 4, 2010

Loading configuration file from Classpath

InputStream is = getClass().getClassLoader().getResourceAsStream(INDEX_CONFIG_FILE);

Thursday, April 29, 2010

JUnit Hibernate Lazy initialization

To configure your JUnit testcases for testing data access through Hibernate with entity mappings using lazy initialization requires minor changes to the setUp() and tearDown() methods as follows:


    /**
     * The application context used in this test case.
     */
    protected ApplicationContext ctx;
    protected StrainDao dao;
    // keep reference to session factory to handle lazy-initialization
    protected SessionFactory sessionFactory;
    protected Session session;
    
    public PhenomeBankTestCase(final String name) {
        super(name);

        // Override the default definition for dataSource
        /*
        final String[] files = {                    
            "file:C:/workspace/mouse/src/main/webapp/WEB-INF/applicationContext-hibernate.xml",
            "classpath:applicationContextDataSource.xml",
            "file:C:/workspace/mouse/src/main/webapp/WEB-INF/phenomeBank-service.xml",             
        };*/
        
        final String[] files = {                    
                "file:./src/main/webapp/WEB-INF/applicationContext-hibernate.xml",
                "classpath:applicationContextDataSource.xml",
                "file:./src/main/webapp/WEB-INF/phenomeBank-service.xml",             
            };        

        ctx = new ClassPathXmlApplicationContext(files);
        sessionFactory = (SessionFactory)ctx.getBean(BEAN_ID_SESSION_FACTORY);
    }
    
    /**
     * Sets up the test fixture.
     */
    @Override
    public void setUp() {
        dao = (StrainDao) ctx.getBean(BEAN_ID_STRAIN_DAO);         

        session = SessionFactoryUtils.getSession(this.sessionFactory, true);
        TransactionSynchronizationManager.bindResource(this.sessionFactory, new SessionHolder(session));        
    }

    @Override
    protected void tearDown() throws Exception {
        TransactionSynchronizationManager.unbindResource(this.sessionFactory);
        SessionFactoryUtils.releaseSession(this.session, this.sessionFactory);
    }



Reference: http://note19.com/2007/08/26/lazy-initialization-with-hibernate-and-spring/

Wednesday, April 28, 2010

Hudson and missing maven repository artifacts

When attempting to make a build in Hudson for the first time, it complained of missing artifacts in the maven repo. I found that I had to configure the MAVEN_HOME/conf/settings.xml file to point to the maven repo by editing the localRepository element

Here's a reference for more details:
http://stackoverflow.com/questions/44144/hudson-cant-build-my-maven-2-project-because-it-says-artifacts-are-missing-from

Once the initial build was working, I had to make additional changes to make maven do a 'clean package'
and perform a build everytime a change gets submitted to SVN as shown below:

Tuesday, April 27, 2010

SFTP: Received message too long 1936094320

The problem:

Recently the server running SFTP was updated with some security patches applied. Soon afterwards, one of the users couldn't connect via SFTP with the following error:


$ sftp broken_user@server

Received message too long 1936094320


 I spent quite a bit of time searching for solutions and most talked about an echo statement in one of the .bashrc or .bash_profile scripts. However, upon inspection I couldn't find any echo statements.

However, I noticed that when I used the root user it worked fine:


$ sftp root@server 

 The solution:

I did manage to find a workaround, although I am still unable to explain why it works.
I ended up editing the /etc/passwd file and changed a line from:


broken_user:x:503:503::/var/websites/my_website/./:/bin/sftpsh

to

broken_user:x:503:503::/var/websites/my_website/./:/bin/bash