Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] What cause this exception

Chris/Tim,

Thank you both for your assistance. Removing the @Basis annotation did indeed fix the problem. 

I guess I have to go back and unlearn/relearn some of my persistence skills :-(

Cheers,
Joel

On 2 Jan 2009, at 17:42, Joel Rosi-Schwartz wrote:

Hi Chris,

Apologies, I did not realise the mailling list was so sensitive to ZIP attachments. I will watch that in the future.

I have pasted the the UsemeSession and ProjectRegistration entities below.

As for why the @Basic, it is simply how I learned to annotate Entities back in Hibernate 3.x. I will try removing the annotation and see what happens.

I this situation there is nothing lost by not using @Basic. But in cases where I need to set the fetch or optional qualities, what is the recommend approach with JPA/Eclipselink?

Thanks,
Joel


On 2 Jan 2009, at 17:30, Christopher Delahunt wrote:

Hello Joel,

 I didn't get the email with your entities, and likely others on the list didn't either if you sent them via a zip file.  I can't say why it is unable to load the IndirectSet class when it attempts to reserialize the enitity though - it seems like an osgi loading issue.  The stack trace shows that an object is marked with a basic mapping that has references to other entities.  This is not recommended, as object identity will not be preserved.  So if ProjectRegistration is marked with a basic mapping, what does it look like? 

 

Best Regards,
Chris

 

 - but I don't see why you would mark an object with a basic map


/*******************************************************************************
 * Copyright (c) 2004, 2008 Etish Limited.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 *
 * Contributors:
 *     Barbara Rosi-Schwartz (Etish Limited, UK) - initial API and implementation
 *     Joel Rosi-Schwartz (Etish Limited, UK) - initial API and implementation
 *******************************************************************************/
package org.eclipse.ormf.server.base.services.domain;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.eclipse.ormf.shared.util.logging.ILogger;
import org.eclipse.ormf.shared.util.logging.Logger;

@Entity(name = "ProjectRegistrations")
@Table(name = "Project_Registrations", schema = "useme")
public class ProjectRegistration implements Serializable {
/**
*/
private static final long serialVersionUID = -6568133198758085217L;

/**
* The instance of the logger for this class.
*/
private static final ILogger logger = Logger
.Instance(ProjectRegistration.class);

/** persistent field */
private Boolean deleted;

/** identifier field */
private Long id;

/** persistent field */
private Boolean open;

/** persistent field */
private Boolean projectAdmin;

/** persistent field */
private Short projectId;

/** persistent field */
private UsemeSession session;

/** persistent field */
private Boolean subscribed;

/** persistent field */
private User user;

private Integer version;

/** default constructor */
public ProjectRegistration() {
}

/** full constructor */
public ProjectRegistration(Short projectId, Boolean projectAdmin, User user) {
this.projectId = projectId;
this.projectAdmin = projectAdmin;
subscribed = false;
open = false;
deleted = false;
this.user = user;
}

/*
* (non-Javadoc)
* @see
* org.eclipse.ormf.server.base.services.persistence.domain.IProjectRegistration
* #closeProject()
*/
public void closeProject() {
open = false;
session = null;
}

@Override
public boolean equals(Object other) {
if ((this == other)) {
return true;
}

if (!(other instanceof ProjectRegistration)) {
return false;
}

final ProjectRegistration castOther = (ProjectRegistration) other;

return new EqualsBuilder().append(getProjectId(),
castOther.getProjectId())
.append(getUser(), castOther.getUser()).isEquals();
}

@Id
@Column(updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}

@Column(name = "project_id", nullable = false)
@Basic(optional = false)
public Short getProjectId() {
return projectId;
}

@Basic
public UsemeSession getSession() {
return session;
}

@ManyToOne
@JoinColumn(name = "user_id", nullable = false, updatable = false)
// FIXME - why does this cause Eclipselink to throw an exception?
// @Basic(optional = false)
public User getUser() {
return user;
}

@Version
protected Integer getVersion() {
return version;
}

@Override
public int hashCode() {
return new HashCodeBuilder().append(getProjectId()).append(getUser())
.toHashCode();
}

public Boolean isDeleted() {
return deleted;
}

@Column(name = "is_open", nullable = false)
@Basic(optional = false)
public Boolean isOpen() {
return open;
}

/*
* (non-Javadoc)
* @see
* org.eclipse.ormf.server.base.services.persistence.domain.IProjectRegistration
* #isProjectAdmin()
*/
@Column(name = "is_project_admin", nullable = false)
@Basic(optional = false)
public Boolean isProjectAdmin() {
return projectAdmin;
}

@Column(name = "is_subscribed", nullable = false)
@Basic(optional = false)
public Boolean isSubscribed() {
return subscribed;
}

public void openProject(final UsemeSession session) {
this.session = session;
open = true;
}

public void setDeleted(Boolean deleted) {
this.deleted = deleted;
}

protected void setId(Long id) {
this.id = id;
}

protected void setOpen(Boolean open) {
this.open = open;
}

public void setProjectAdmin(Boolean projectAdmin) {
this.projectAdmin = projectAdmin;
}

protected void setProjectId(Short projectId) {
this.projectId = projectId;
}

protected void setSession(UsemeSession session) {
this.session = session;
}

public void setSubscribed(Boolean subscribed) {
this.subscribed = subscribed;
}

protected void setUser(User user) {
this.user = user;
}

protected void setVersion(Integer version) {
this.version = version;
}

@Override
public String toString() {
return new ToStringBuilder(this).append("id", getId()).append(
"projectId", getProjectId()).append("user", getUser())
.toString();
}
}

/*******************************************************************************
 * Copyright (c) 2004, 2008 Etish Limited.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 *
 * Contributors:
 *     Barbara Rosi-Schwartz (Etish Limited, UK) - initial API and implementation
 *     Joel Rosi-Schwartz (Etish Limited, UK) - initial API and implementation
 *******************************************************************************/
package org.eclipse.ormf.server.base.services.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

import org.apache.commons.lang.builder.ToStringBuilder;

@Entity(name = "UsemeSessions")
@Table(name = "Useme_Sessions", schema = "useme")
public class UsemeSession implements Serializable {
/**
*/
private static final long serialVersionUID = 5138480260250493275L;

/** nullable persistent field */
private Date closedOn;

/** persistent field */
private Date createdOn;

/** nullable persistent field */
private User hijackedBy;

/** nullable persistent field */
private Date hijackedOn;

/** persistent field */
private String hostId;

/** identifier field */
private Long id;

/** persistent field */
private boolean open;

/** persistent field */
private Long sessionId;

/** persistent field */
private User user;

/** nullable persistent field */
private Integer version;

/** default constructor */
protected UsemeSession() {
}

/** minimal constructor */
public UsemeSession(String hostId, User user) {
sessionId = System.currentTimeMillis();
createdOn = new Date();
open = true;
this.hostId = hostId;
this.user = user;
}

public void close() {
setOpen(false);
setClosedOn(new Date());
}

@Override
public boolean equals(Object other) {
if ((this == other)) {
return true;
}

if (!(other instanceof UsemeSession)) {
return false;
}

final UsemeSession castOther = (UsemeSession) other;

return getSessionId() == castOther.getSessionId();
}

@Column(name = "closed_on")
@Temporal(TemporalType.TIMESTAMP)
public Date getClosedOn() {
return closedOn;
}

@Column(name = "created_on", nullable = false, updatable = false)
@Temporal(TemporalType.TIMESTAMP)
@Basic(optional = false)
public Date getCreatedOn() {
return createdOn;
}

@ManyToOne
public User getHijackedBy() {
return hijackedBy;
}

@Column(name = "hijacked_on")
@Temporal(TemporalType.TIMESTAMP)
public Date getHijackedOn() {
return hijackedOn;
}

@Column(name = "host_id", length = 64, nullable = false, updatable = false)
@Basic(optional = false)
public String getHostId() {
return hostId;
}

@Id
@Column(updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}

@Column(name = "session_id", nullable = false, updatable = false)
@Basic(optional = false)
public Long getSessionId() {
return sessionId;
}

@ManyToOne
// @Basic(optional = false)
public User getUser() {
return user;
}

@Version
protected Integer getVersion() {
return version;
}

@Override
public int hashCode() {
return new Long(sessionId).hashCode();
}

public void hijack(User by) {
setHijackedBy(by);
setHijackedOn(new Date());
setClosedOn(new Date());
setOpen(false);
}

@Column(name = "is_open", nullable = false)
@Basic(optional = false)
public boolean isOpen() {
return open;
}

protected void setClosedOn(Date closedOn) {
this.closedOn = closedOn;
}

protected void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}

protected void setHijackedBy(User hijackedBy) {
this.hijackedBy = hijackedBy;
}

protected void setHijackedOn(Date hijackedOn) {
this.hijackedOn = hijackedOn;
}

protected void setHostId(String hostId) {
this.hostId = hostId;
}

protected void setId(Long id) {
this.id = id;
}

protected void setOpen(boolean open) {
this.open = open;
}

protected void setSessionId(Long sessionId) {
this.sessionId = sessionId;
}

protected void setUser(User user) {
this.user = user;
}

protected void setVersion(Integer version) {
this.version = version;
}

@Override
public String toString() {
return new ToStringBuilder(this).append("id", getId()).append(
"sessionId", getSessionId()).append("user", getUser())
.toString();
}
}
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top