### Eclipse Workspace Patch 1.0
#P james-server-spring-deployment
Index: src/main/config/james/META-INF/persistence.xml
===================================================================
--- src/main/config/james/META-INF/persistence.xml	(revision 980373)
+++ src/main/config/james/META-INF/persistence.xml	(working copy)
@@ -8,8 +8,8 @@
         <!-- Mailbox stuff-->
         <class>org.apache.james.imap.jpa.mail.model.JPAHeader</class>
         <class>org.apache.james.imap.jpa.mail.model.JPAMailbox</class>
-        <class>org.apache.james.imap.jpa.mail.model.AbstractJPAMessage</class>
-        <class>org.apache.james.imap.jpa.mail.model.AbstractJPAMailboxMembership</class>
+        <class>org.apache.james.imap.jpa.mail.model.openjpa.AbstractJPAMessage</class>
+        <class>org.apache.james.imap.jpa.mail.model.openjpa.AbstractJPAMailboxMembership</class>
         <!-- This needs to get used when you want to use streaming. Remember to comment the following classes
              org.apache.james.imap.jpa.mail.model.JPAMailboxMembership
              org.apache.james.imap.jpa.mail.model.JPAMessage
#P apache-james-imap-deployment
Index: src/test/java/org/apache/james/imap/functional/jpa/JPAStressTest.java
===================================================================
--- src/test/java/org/apache/james/imap/functional/jpa/JPAStressTest.java	(revision 980376)
+++ src/test/java/org/apache/james/imap/functional/jpa/JPAStressTest.java	(working copy)
@@ -27,7 +27,14 @@
 import org.apache.james.imap.functional.AbstractStressTest;
 import org.apache.james.imap.jpa.JPAMailboxSessionMapperFactory;
 import org.apache.james.imap.jpa.JPASubscriptionManager;
+import org.apache.james.imap.jpa.mail.model.JPAMailbox;
+import org.apache.james.imap.jpa.mail.model.JPAMailboxMembership;
+import org.apache.james.imap.jpa.mail.model.JPAMessage;
+import org.apache.james.imap.jpa.mail.model.JPAProperty;
+import org.apache.james.imap.jpa.mail.model.openjpa.AbstractJPAMailboxMembership;
+import org.apache.james.imap.jpa.mail.model.openjpa.AbstractJPAMessage;
 import org.apache.james.imap.jpa.openjpa.OpenJPAMailboxManager;
+import org.apache.james.imap.jpa.user.model.JPASubscription;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.store.StoreMailboxManager;
@@ -54,13 +61,13 @@
         properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72");
         properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
         properties.put("openjpa.MetaDataFactory", "jpa(Types=org.apache.james.imap.jpa.mail.model.JPAHeader;" +
-                "org.apache.james.imap.jpa.mail.model.JPAMailbox;" +
-                "org.apache.james.imap.jpa.mail.model.AbstractJPAMailboxMembership;" +
-                "org.apache.james.imap.jpa.mail.model.JPAMailboxMembership;" +
-                "org.apache.james.imap.jpa.mail.model.AbstractJPAMessage;" +
-                "org.apache.james.imap.jpa.mail.model.JPAMessage;" +
-                "org.apache.james.imap.jpa.mail.model.JPAProperty;" +
-                "org.apache.james.imap.jpa.user.model.JPASubscription)");
+                JPAMailbox.class.getName() + ";" +
+                AbstractJPAMailboxMembership.class.getName() + ";" +
+                JPAMailboxMembership.class.getName() + ";" +
+                AbstractJPAMessage.class.getName() + ";" +
+                JPAMessage.class.getName() + ";" +
+                JPAProperty.class.getName() + ";" +
+                JPASubscription.class.getName() + ")");
         properties.put("openjpa.LockTimeout", locktimeout + "");
        
         entityManagerFactory = OpenJPAPersistence.getEntityManagerFactory(properties);
#P apache-james-imap-jpa
Index: src/main/java/org/apache/james/imap/jpa/mail/model/AbstractJPAMessage.java
===================================================================
--- src/main/java/org/apache/james/imap/jpa/mail/model/AbstractJPAMessage.java	(revision 980373)
+++ src/main/java/org/apache/james/imap/jpa/mail/model/AbstractJPAMessage.java	(working copy)
@@ -1,203 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.imap.jpa.mail.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.Basic;
-import javax.persistence.CascadeType;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.MappedSuperclass;
-import javax.persistence.OneToMany;
-import javax.persistence.OrderBy;
-
-import org.apache.james.imap.store.mail.model.AbstractDocument;
-import org.apache.james.imap.store.mail.model.Document;
-import org.apache.james.imap.store.mail.model.Header;
-import org.apache.james.imap.store.mail.model.Property;
-import org.apache.james.imap.store.mail.model.PropertyBuilder;
-
-/**
- * Abstract base class for JPA based implementations of {@link AbstractDocument}
- *
- */
-@MappedSuperclass
-public abstract class AbstractJPAMessage extends AbstractDocument{
-
-    @Id@GeneratedValue private long id;
-
-    /** Headers for this message */
-    @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY) private List<JPAHeader> headers;
-    /** The first body octet */
-    @Basic(optional=false) private int bodyStartOctet;
-    /** Number of octets in the full document content */
-    @Basic(optional=false) private long contentOctets;
-    /** MIME media type */
-    @Basic(optional=true) private String mediaType;
-    /** MIME sub type */
-    @Basic(optional=true) private String subType;
-    /** Meta data for this message */
-    @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY) @OrderBy("line") private List<JPAProperty> properties;
-    /** THE CRFL count when this document is textual, null otherwise */
-    @Basic(optional=true) private Long textualLineCount;
-    
-
-    @Deprecated
-    public AbstractJPAMessage() {}
-
-    public AbstractJPAMessage(final long contentOctets, final int bodyStartOctet, final List<JPAHeader> headers, final PropertyBuilder propertyBuilder) {
-        super();
-        this.contentOctets = contentOctets;
-        this.bodyStartOctet = bodyStartOctet;
-        this.headers = new ArrayList<JPAHeader>(headers);
-        textualLineCount = propertyBuilder.getTextualLineCount();
-        this.mediaType = propertyBuilder.getMediaType();
-        this.subType = propertyBuilder.getSubType();
-        final List<Property> properties = propertyBuilder.toProperties();
-        this.properties = new ArrayList<JPAProperty>(properties.size());
-        int order = 0;
-        for (final Property property:properties) {
-            this.properties.add(new JPAProperty(property, order++));
-        }
-
-    }
-
-    /**
-     * Create a copy of the given message
-     * 
-     * @param message
-     */
-    public AbstractJPAMessage(Document message) {
-    	
-        this.contentOctets = message.getFullContentOctets();
-        this.bodyStartOctet = (int) (message.getFullContentOctets() - message.getBodyOctets());
-        this.headers = new ArrayList<JPAHeader>();
-        
-        List<Header> originalHeaders = message.getHeaders();
-        for (int i = 0; i < originalHeaders.size(); i++) {
-            headers.add(new JPAHeader(originalHeaders.get(i)));
-        }
-
-        PropertyBuilder pBuilder = new PropertyBuilder(message.getProperties());
-        this.textualLineCount = pBuilder.getTextualLineCount();
-        this.mediaType = pBuilder.getMediaType();
-        this.subType = pBuilder.getSubType();
-        final List<Property> properties = pBuilder.toProperties();
-        this.properties = new ArrayList<JPAProperty>(properties.size());
-        int order = 0;
-        for (final Property property:properties) {
-            this.properties.add(new JPAProperty(property, order++));
-        }
-
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.Document#getHeaders()
-     */
-    public List<Header> getHeaders() {
-        return new ArrayList<Header>(headers);
-    }
-
-
-    @Override
-    public int hashCode() {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + (int) (id ^ (id >>> 32));
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        final AbstractJPAMessage other = (AbstractJPAMessage) obj;
-        if (id != other.id)
-            return false;
-        return true;
-    }
-
-    public String toString()
-    {
-        final String retValue = 
-            "message("
-            + "id = " + id
-            + " )";
-        return retValue;
-    }
-
-    /**
-     * Gets the top level MIME content media type.
-     * 
-     * @return top level MIME content media type, or null if default
-     */
-    public String getMediaType() {
-        return mediaType;
-    }
-    
-    /**
-     * Gets the MIME content subtype.
-     * 
-     * @return the MIME content subtype, or null if default
-     */
-    public String getSubType() {
-        return subType;
-    }
-
-    /**
-     * Gets a read-only list of meta-data properties.
-     * For properties with multiple values, this list will contain
-     * several enteries with the same namespace and local name.
-     * @return unmodifiable list of meta-data, not null
-     */
-    public List<Property> getProperties() {
-        return new ArrayList<Property>(properties);
-    }
-    
-    /**
-     * Gets the number of CRLF in a textual document.
-     * @return CRLF count when document is textual,
-     * null otherwise
-     */
-    public Long getTextualLineCount() {
-        return textualLineCount;
-    }
-
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.model.Document#getFullContentOctets()
-     */
-    public long getFullContentOctets() {
-        return contentOctets;
-    }
-
-    @Override
-    protected int getBodyStartOctet() {
-        return bodyStartOctet;
-    }
-
-}
Index: src/main/java/org/apache/james/imap/jpa/mail/model/JPAMessage.java
===================================================================
--- src/main/java/org/apache/james/imap/jpa/mail/model/JPAMessage.java	(revision 980373)
+++ src/main/java/org/apache/james/imap/jpa/mail/model/JPAMessage.java	(working copy)
@@ -29,6 +29,7 @@
 import javax.persistence.FetchType;
 import javax.persistence.Lob;
 
+import org.apache.james.imap.jpa.mail.model.openjpa.AbstractJPAMessage;
 import org.apache.james.imap.store.mail.model.Document;
 import org.apache.james.imap.store.mail.model.PropertyBuilder;
 import org.apache.james.imap.store.streaming.StreamUtils;
Index: src/main/java/org/apache/james/imap/jpa/mail/model/AbstractJPAMailboxMembership.java
===================================================================
--- src/main/java/org/apache/james/imap/jpa/mail/model/AbstractJPAMailboxMembership.java	(revision 980373)
+++ src/main/java/org/apache/james/imap/jpa/mail/model/AbstractJPAMailboxMembership.java	(working copy)
@@ -1,313 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.imap.jpa.mail.model;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.Date;
-import java.util.List;
-
-import javax.mail.Flags;
-import javax.persistence.Basic;
-import javax.persistence.Id;
-import javax.persistence.IdClass;
-import javax.persistence.MappedSuperclass;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
-
-import org.apache.james.imap.mailbox.MailboxException;
-import org.apache.james.imap.store.mail.model.AbstractMailboxMembership;
-import org.apache.james.imap.store.mail.model.MailboxMembership;
-import org.apache.james.imap.store.mail.model.PropertyBuilder;
-
-@MappedSuperclass
-@IdClass(AbstractJPAMailboxMembership.MailboxIdUidKey.class)
-@NamedQueries({
-    @NamedQuery(name="findRecentMessagesInMailbox",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.recent = TRUE"),
-    @NamedQuery(name="findUnseenMessagesInMailboxOrderByUid",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.seen = FALSE ORDER BY membership.uid ASC"),
-    @NamedQuery(name="findMessagesInMailbox",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam"),
-    @NamedQuery(name="findMessagesInMailboxBetweenUIDs",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.uid BETWEEN :fromParam AND :toParam"),        
-    @NamedQuery(name="findMessagesInMailboxWithUID",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.uid=:uidParam"),                    
-    @NamedQuery(name="findMessagesInMailboxAfterUID",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.uid>=:uidParam"),                    
-    @NamedQuery(name="findDeletedMessagesInMailbox",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.deleted=TRUE"),                   
-    @NamedQuery(name="findDeletedMessagesInMailboxBetweenUIDs",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.uid BETWEEN :fromParam AND :toParam AND membership.deleted=TRUE"),        
-    @NamedQuery(name="findDeletedMessagesInMailboxWithUID",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.uid=:uidParam AND membership.deleted=TRUE"),                    
-    @NamedQuery(name="findDeletedMessagesInMailboxAfterUID",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.uid>=:uidParam AND membership.deleted=TRUE"),                    
-    @NamedQuery(name="countUnseenMessagesInMailbox",
-            query="SELECT COUNT(membership) FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.seen=FALSE"),                     
-    @NamedQuery(name="countMessagesInMailbox",
-            query="SELECT COUNT(membership) FROM Membership membership WHERE membership.mailboxId = :idParam"),                    
-    @NamedQuery(name="deleteMessages",
-            query="DELETE FROM Membership membership WHERE membership.mailboxId = :idParam") 
-})
-public abstract class AbstractJPAMailboxMembership extends AbstractMailboxMembership<Long> {
-
-    private static final String TOSTRING_SEPARATOR = " ";
-
-    /** Identifies composite key */
-    public static class MailboxIdUidKey implements Serializable {
-        private static final long serialVersionUID = 7847632032426660997L;
-        /** The value for the mailboxId field */
-        public long mailboxId;
-        /** The value for the uid field */
-        public long uid;
-
-        public MailboxIdUidKey() {}
-
-        @Override
-        public int hashCode() {
-            final int PRIME = 31;
-            int result = 1;
-            result = PRIME * result + (int) (mailboxId ^ (mailboxId >>> 32));
-            result = PRIME * result + (int) (uid ^ (uid >>> 32));
-            return result;
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            if (this == obj)
-                return true;
-            if (obj == null)
-                return false;
-            if (getClass() != obj.getClass())
-                return false;
-            final MailboxIdUidKey other = (MailboxIdUidKey) obj;
-            if (mailboxId != other.mailboxId)
-                return false;
-            if (uid != other.uid)
-                return false;
-            return true;
-        }
-    }
-
-    /** The value for the mailboxId field */
-    @Id private long mailboxId;
-
-    /** The value for the uid field */
-    @Id private long uid;
-
-    /** The value for the internalDate field */
-    @Basic(optional=false) private Date internalDate;
-
-    /** The value for the size field */
-    @Basic(optional=false) private int size = 0;
-
-    /** The value for the answered field */
-    @Basic(optional=false) private boolean answered = false;
-
-    /** The value for the deleted field */
-    @Basic(optional=false) private boolean deleted = false;
-
-    /** The value for the draft field */
-    @Basic(optional=false) private boolean draft = false;
-
-    /** The value for the flagged field */
-    @Basic(optional=false) private boolean flagged = false;
-
-    /** The value for the recent field */
-    @Basic(optional=false) private boolean recent = false;
-
-    /** The value for the seen field */
-    @Basic(optional=false) private boolean seen = false;
-
-    
-    /**
-     * For enhancement only.
-     */
-    @Deprecated
-    public AbstractJPAMailboxMembership() {}
-
-    public AbstractJPAMailboxMembership(long mailboxId, long uid, Date internalDate, int size, Flags flags, int bodyStartOctet, final List<JPAHeader> headers, final PropertyBuilder propertyBuilder) throws MailboxException {
-        super();
-        this.mailboxId = mailboxId;
-        this.uid = uid;
-        this.internalDate = internalDate;
-        this.size = size;
-       
-        setFlags(flags);
-    }
-
-    /**
-     * Constructs a copy of the given message.
-     * All properties are cloned except mailbox and UID.
-     * @param mailboxId new mailbox ID
-     * @param uid new UID
-     * @param original message to be copied, not null
-     * @throws IOException 
-     */
-    public AbstractJPAMailboxMembership(long mailboxId, long uid, MailboxMembership<?> original) throws MailboxException {
-        super();
-        this.mailboxId = mailboxId;
-        this.uid = uid;
-        this.internalDate = original.getInternalDate();
-        this.size = original.getSize();
-        this.answered = original.isAnswered();
-        this.deleted = original.isDeleted();
-        this.draft = original.isDraft();
-        this.flagged = original.isFlagged();
-        this.recent = original.isRecent();
-        this.seen = original.isSeen();
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#getInternalDate()
-     */
-    public Date getInternalDate() {
-        return internalDate;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#getMailboxId()
-     */
-    public Long getMailboxId() {
-        return mailboxId;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#getSize()
-     */
-    public int getSize() {
-        return size;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#getUid()
-     */
-    public long getUid() {
-        return uid;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#isAnswered()
-     */
-    public boolean isAnswered() {
-        return answered;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#isDeleted()
-     */
-    public boolean isDeleted() {
-        return deleted;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#isDraft()
-     */
-    public boolean isDraft() {
-        return draft;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#isFlagged()
-     */
-    public boolean isFlagged() {
-        return flagged;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#isRecent()
-     */
-    public boolean isRecent() {
-        return recent;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#isSeen()
-     */
-    public boolean isSeen() {
-        return seen;
-    }
-    
-  
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#unsetRecent()
-     */
-    public void unsetRecent() {
-        recent = false;
-    }
-    
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#setFlags(javax.mail.Flags)
-     */
-    public void setFlags(Flags flags) {
-        answered = flags.contains(Flags.Flag.ANSWERED);
-        deleted = flags.contains(Flags.Flag.DELETED);
-        draft = flags.contains(Flags.Flag.DRAFT);
-        flagged = flags.contains(Flags.Flag.FLAGGED);
-        recent = flags.contains(Flags.Flag.RECENT);
-        seen = flags.contains(Flags.Flag.SEEN);
-    }
-
-  
-
-    @Override
-    public int hashCode() {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + (int) (mailboxId ^ (mailboxId >>> 32));
-        result = PRIME * result + (int) (uid ^ (uid >>> 32));
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        final AbstractJPAMailboxMembership other = (AbstractJPAMailboxMembership) obj;
-        if (mailboxId != other.mailboxId)
-            return false;
-        if (uid != other.uid)
-            return false;
-        return true;
-    }
-
-    public String toString()
-    {
-        final String retValue = 
-            "mailbox("
-            + "mailboxId = " + this.mailboxId + TOSTRING_SEPARATOR
-            + "uid = " + this.uid + TOSTRING_SEPARATOR
-            + "internalDate = " + this.internalDate + TOSTRING_SEPARATOR
-            + "size = " + this.size + TOSTRING_SEPARATOR
-            + "answered = " + this.answered + TOSTRING_SEPARATOR
-            + "deleted = " + this.deleted + TOSTRING_SEPARATOR
-            + "draft = " + this.draft + TOSTRING_SEPARATOR
-            + "flagged = " + this.flagged + TOSTRING_SEPARATOR
-            + "recent = " + this.recent + TOSTRING_SEPARATOR
-            + "seen = " + this.seen + TOSTRING_SEPARATOR
-            + " )";
-
-        return retValue;
-    }
-}
Index: src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java
===================================================================
--- src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java	(revision 980373)
+++ src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java	(working copy)
@@ -30,6 +30,7 @@
 import javax.persistence.ManyToOne;
 
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.jpa.mail.model.openjpa.AbstractJPAMailboxMembership;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.store.mail.model.Document;
 import org.apache.james.imap.store.mail.model.PropertyBuilder;
Index: src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/AbstractJPAMessage.java
===================================================================
--- src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/AbstractJPAMessage.java	(revision 980373)
+++ src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/AbstractJPAMessage.java	(working copy)
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-package org.apache.james.imap.jpa.mail.model;
+package org.apache.james.imap.jpa.mail.model.openjpa;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -30,11 +30,14 @@
 import javax.persistence.OneToMany;
 import javax.persistence.OrderBy;
 
+import org.apache.james.imap.jpa.mail.model.JPAHeader;
+import org.apache.james.imap.jpa.mail.model.JPAProperty;
 import org.apache.james.imap.store.mail.model.AbstractDocument;
 import org.apache.james.imap.store.mail.model.Document;
 import org.apache.james.imap.store.mail.model.Header;
 import org.apache.james.imap.store.mail.model.Property;
 import org.apache.james.imap.store.mail.model.PropertyBuilder;
+import org.apache.openjpa.persistence.jdbc.ElementJoinColumn;
 
 /**
  * Abstract base class for JPA based implementations of {@link AbstractDocument}
@@ -46,7 +49,7 @@
     @Id@GeneratedValue private long id;
 
     /** Headers for this message */
-    @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY) private List<JPAHeader> headers;
+    @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY) @ElementJoinColumn(name="MESSAGE_ID") private List<JPAHeader> headers;
     /** The first body octet */
     @Basic(optional=false) private int bodyStartOctet;
     /** Number of octets in the full document content */
@@ -56,7 +59,7 @@
     /** MIME sub type */
     @Basic(optional=true) private String subType;
     /** Meta data for this message */
-    @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY) @OrderBy("line") private List<JPAProperty> properties;
+    @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY) @OrderBy("line") @ElementJoinColumn(name="MESSAGE_ID") private List<JPAProperty> properties;
     /** THE CRFL count when this document is textual, null otherwise */
     @Basic(optional=true) private Long textualLineCount;
     
Index: src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/AbstractJPAMailboxMembership.java
===================================================================
--- src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/AbstractJPAMailboxMembership.java	(revision 980373)
+++ src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/AbstractJPAMailboxMembership.java	(working copy)
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-package org.apache.james.imap.jpa.mail.model;
+package org.apache.james.imap.jpa.mail.model.openjpa;
 
 import java.io.IOException;
 import java.io.Serializable;
@@ -31,10 +31,12 @@
 import javax.persistence.NamedQueries;
 import javax.persistence.NamedQuery;
 
+import org.apache.james.imap.jpa.mail.model.JPAHeader;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.store.mail.model.AbstractMailboxMembership;
 import org.apache.james.imap.store.mail.model.MailboxMembership;
 import org.apache.james.imap.store.mail.model.PropertyBuilder;
+import org.apache.openjpa.persistence.jdbc.Index;
 
 @MappedSuperclass
 @IdClass(AbstractJPAMailboxMembership.MailboxIdUidKey.class)
@@ -122,7 +124,7 @@
     @Basic(optional=false) private boolean answered = false;
 
     /** The value for the deleted field */
-    @Basic(optional=false) private boolean deleted = false;
+    @Basic(optional=false) @Index private boolean deleted = false;
 
     /** The value for the draft field */
     @Basic(optional=false) private boolean draft = false;
@@ -131,10 +133,10 @@
     @Basic(optional=false) private boolean flagged = false;
 
     /** The value for the recent field */
-    @Basic(optional=false) private boolean recent = false;
+    @Basic(optional=false) @Index private boolean recent = false;
 
     /** The value for the seen field */
-    @Basic(optional=false) private boolean seen = false;
+    @Basic(optional=false) @Index private boolean seen = false;
 
     
     /**
Index: src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMailboxMembership.java
===================================================================
--- src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMailboxMembership.java	(revision 980373)
+++ src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMailboxMembership.java	(working copy)
@@ -30,7 +30,6 @@
 import javax.persistence.ManyToOne;
 
 import org.apache.james.imap.api.display.HumanReadableText;
-import org.apache.james.imap.jpa.mail.model.AbstractJPAMailboxMembership;
 import org.apache.james.imap.jpa.mail.model.JPAHeader;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.store.mail.model.Document;
Index: src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMessage.java
===================================================================
--- src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMessage.java	(revision 980373)
+++ src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMessage.java	(working copy)
@@ -28,7 +28,6 @@
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
 
-import org.apache.james.imap.jpa.mail.model.AbstractJPAMessage;
 import org.apache.james.imap.jpa.mail.model.JPAHeader;
 import org.apache.james.imap.jpa.mail.model.JPAMessage;
 import org.apache.james.imap.store.mail.model.Document;
Index: src/main/java/org/apache/james/imap/jpa/mail/JPAMessageMapper.java
===================================================================
--- src/main/java/org/apache/james/imap/jpa/mail/JPAMessageMapper.java	(revision 980373)
+++ src/main/java/org/apache/james/imap/jpa/mail/JPAMessageMapper.java	(working copy)
@@ -26,8 +26,8 @@
 
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.jpa.JPATransactionalMapper;
-import org.apache.james.imap.jpa.mail.model.AbstractJPAMailboxMembership;
 import org.apache.james.imap.jpa.mail.model.JPAMailboxMembership;
+import org.apache.james.imap.jpa.mail.model.openjpa.AbstractJPAMailboxMembership;
 import org.apache.james.imap.jpa.mail.model.openjpa.JPAStreamingMailboxMembership;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MessageRange;
