Archive

Archive for August, 2008

Maven4MyEclipse Bug

August 27th, 2008 No comments

I have not been quite impressed with MyEclipse’s Maven4MyEclipse plugin. The most disappointing thing about this is that after checking out an existing project from source control, I cannot add Maven “capabilities” using the context menu (which could be easily done with m2eclipse).

For the last couple days, I am running into this wierd bug with the “Java Maven Wizard”: When I try to check out an existing project from SVN using: “Find/Check Out As” -> “Check Out as a project configured using the New Project Wizard” -> “Java Maven Project” into a location other than the default location provided by the wizard, the wizard still checks out the project into the default location.

Hopefully I will have some solution in the Maven4MyEclipse forum.

Update: Looks like the same issue surfaces for newly created Java Maven projects also.

Categories: Maven, MyEclipse Tags:

WebLogic anonymous user permissioning

August 26th, 2008 No comments

Problem: Accessing MBeans in WebLogic versions 8.1 SP5 and after results in
javax.naming.NoPermissionException: User <anonymous> does not have permission on weblogic.management.home to perform lookup operation.

Solution:  A quick fix to this problem is to enable anonymous admin lookup in WebLogic server. In WebLogic 10, this option is available under Security tab of the domain.

Categories: Solutions Log Tags:

Eclipse -clean

August 25th, 2008 3 comments

Here is a small tip for eclipse users: running eclipse with -clean option once in a while can improve its startup time.

The clean option removes any cached data stored by eclipse runtime and forces cache reinitialization.

Categories: Solutions Log Tags:

Maven heap size

August 25th, 2008 2 comments

The heap size of the Jvm used by Maven (invoked via mvn.bat) can be changed using MAVEN_OPTS parameter at the OS level. For windows, this would be an environment variable.

Variable name: MAVEN_OPTS

Variable value: -Xmx512m

Categories: Solutions Log Tags:

Sending a message to JMS Queue

August 20th, 2008 No comments

Here is some code to send a message to a JMS queue using Spring:

ConnectionFactory connectionFactory = // Look up connectionfactory from JNDI
    Queue queue = // Look up distributed queue from JNDI
    JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
    jmsTemplate.send(queue, new MessageCreator() {
        public Message createMessage(Session sessionthrows JMSException
        {
          ObjectMessage message = session.createObjectMessage();
          // Set the message content
          message.setObject(new Object());
          return message;
        } }
    );

Categories: Uncategorized Tags:

When you are gone for a month….

August 19th, 2008 No comments

… grass grows on your keyboard 🙂

While I was on vaccation, Matt came up with this evil plan to water and grow grass on my keyboard.

Categories: Fun Tags:

Hibernate Ldap bridge

August 19th, 2008 5 comments

It is not uncommon for enterprises to store their employee information in LDAP. Now this poses an interesting challenge for building ORM applications that need access to employee information. For example, consider writing an application that tracks the projects an employee is currently working on. Such an application would have the following simple domain model:

An ORM mapping tool such as Hibernate can easily map this domain model to a database backend. However, since the employee data comes from LDAP, hibernate out of box cannot create the mapping between Project and Employee domain objects. One way to solve this problem would be to implement a custom EntityPersister. In this post I will show a simple hack for achieving this using JPA EntityListeners.

First let us create Java objects and relationships between them. Here is some minimal code:

public class Employee implements Serializable
{
  private Long id;
  private String firstName;
  private String lastName;
  
  // Other fields, getters, setters and other logic
}

public class Project implements Serializable
{
  private Long Id;
  private String name;
  private String description;
  
  private Employee employee;
  
  // Getters, setters and other logic  
}

The next step is to define tables in the database. Here is the table structure:

PROJECT
———–
PROJECT_ID | NAME | DESCRIPTION | EMPLOYEE_ID |

EMPLOYEE
—————-
EMPLOYEE_ID |
Since all the employee information (including EMPLOYEE_ID) is available in LDAP, this table simply holds the unique id of an employee.

Then, create mappings for the domain objects using JPA. The mapping for Application is straightforward:

@Entity
@Table(name="PROJECT")
public class Project implements Serializable 
{
  @Id
  @Column(name="PROJECT_ID")
  // Sequence generator declarations
  private Long Id;
  
  @Column(name="NAME")
  private String name;
  
  @Column(name="DESCRIPTION")
  private String description;
  
  @ManyToOne(cascade= {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
  @JoinColumn(name="EMPLOYEE_ID")
  private Employee employee;

  // Getters, setters and other logic  
}

@Entity
@Table(name="EMPLOYEE")
public class Employee implements Serializable
{
  @Id
  @GeneratedValue(generator="assigned")
  @GenericGenerator(name="assigned", strategy="assigned")
  @Column(name="EMPLOYEE_ID")
  private Long id;
  
  @Transient
  private String firstName;
  
  @Transient
  private String lastName;
  
  // Getters, setters and other logic
}

With these mappings in place, hibernate can easily load the Project
object and the corresponding Employee object. To populate the
transient fields in the Employee object, an EntityListener needs to be
created. Here is a simple implementation for the entity listener:

public class EmployeeEntityListener
{
  @PostLoad
  public void loadEmployee(Employee employee)
  {
    Map<String, String> employeeData = // Read the employee data from LDAP using the employee Id as the key
    employee.setFirstName(employeeData.get("FIRST_NAME"));
    employee.setLastName(employeeData.get("LAST_NAME"));
  }
}

Finally register this entitylistener:

@Entity
@Table(name="EMPLOYEE")
@EntityListeners(EmployeeEntityListener.class)
public class Employee implements Serializable
{
  ——-

Categories: Hibernate Tags: , ,