Thursday, February 15, 2007

TopLink and Dali at EclipseCon 2007

EclipseCon runs from March 5th to 8th this year and I'm involved with a number of sessions relating to Dali and TopLink. If you'll be there I hope you'll consider checking them out.

The first is a short tutorial on Dali on Monday at 10:30. Neil Hauge, my co-lead on Dali will be co-presenting. It'll involve some hands on so bring a laptop. The tutorial number and title is (3633) Building applications with WTP - Java Persistence API (JPA).

If you can't make the tutorial but want to find out more about Dali, Neil and I will be giving the demo session the Dali Java Persistence API Tools Project on Wednesday at 14:30.

On a non-Dali topic, I'll be co-presenting with Stephan Eberle of Bosch a demo session entitled Integrating EMF with JPA--Enabling Enterprise Data Access for RCP Applications where we'll describe and demo the results of our collaboration. That's scheduled for Wednesday at 16:30.

Hope to see you there!

--Shaun

Monday, February 5, 2007

Read-Only JPA Entities

This came up on the TopLink Forum last week but for those who don't read all the postings I thought I'd repeat the information here.

The question was whether it's possible to have read-only Entities in JPA. This isn't in the spec but is possible in TopLink Essentials. You do it by calling the setReadOnly() method on an Entity's TopLink descriptor. One way to do this is through a descriptor customizer.

For example, in persistence.xml:

<property
  name="toplink.descriptor.customizer.Title"
  value="comics.toplink.TitleCustomizer"/>


And a definition of TitleCustomizer implementing oracle.toplink.essentials.tools.sessionconfiguration.DescriptorCustomizer.

public class TitleCustomizer implements DescriptorCustomizer {

public void customize(ClassDescriptor desc) throws Exception {
desc.setReadOnly();
}
}


The semantics of read-only are that any changes you make to an object will not be written to the database, but you are not prevented from making changes.

--Shaun

Wednesday, January 17, 2007

Accessing the Session in TopLink Essentials

Although TopLink Essentials is the reference implementation for JPA, it was derived from Oracle TopLink and therefore shares the same core concepts and classes. Recently I was writing some (admittedly bizarre) JPA code and wanted to verify what was in the shared cache. Of course there's no way to look in the TopLink shared cache using JPA so I needed to use the TopLink API. Fortuately, it's still there if you need it.

To obtain a reference to a session in TopLink Essentials(as in Oracle TopLink) you use the SessionManager. Once you have the session you need, you can use it as you would in Oracle TopLink:


Session session = SessionManager.getManager().getSession("library");
List books = session.readAllObjects(BookImpl.class);
assertEquals("num books", 1, books.size());


The "library" session is the TopLink object underlying the JPA "library" persistence unit as defined in my persistence.xml. But, to make the library session available through the SessionManager you have to add a property to your persistence unit:


<?xml version="1.0" encoding="UTF-8"?>
<persistence>
  <persistence-unit name="library">
    <properties>
      <property name="toplink.session-name" value="library">
...


By adding this declaration you're effectively publishing your "library" persistence unit under a session name of "library". You could publish your persistence unit under a different session name but why confuse matters.

Monday, January 15, 2007

You have to start sometime...

Like many before me here I am posting my first blog entry. This day had to come eventually ;-).

I'm going to be blogging on TopLink related topics--both Oracle TopLink and the open source TopLink Essentials--as well as on the Java Persistence API (JPA) in general. I'll also share news about the Eclipse Dali JPA Tools project which I'm involved with. Dali's heading for 1.0 in June as part of the Eclipse Europa release so there's lots of work going on there.

I'd created this account a few days ago and was looking for a topic for my first blog but before I found it I read an interesting blog by Mike Milinkovich on the recent announcement of people named ACM Distinguished Engineers and thought I'd add a comment. And when I did, it linked my comments to my blog--and it was as yet blank. So here I am. Hopefully subsequent entries will be more substantial.

--Shaun