Looking deeper at Hibernate's source code, I see that the IdentifierGenerator does not come from the session, but from the EntityMetamodel for the object being persisted. So perhaps the issue comes from how the objects are mapped. Here's the code for both the Mystic Paste object (PasteItem.java) and my object (Referral.java)
/**
* @author <a href="mailto:
[email protected]">Guillermo Castro</a>
* @version $Revision$ $Date$
*/
@Entity
@Table(name = "PASTE_ITEMS")
@NamedQueries({@NamedQuery(name = "item.getById",
query = "from PasteItem item where item.id = :id"),
@NamedQuery(name = "item.find",
query = "from PasteItem item where item.isPrivate <> true AND item.abuseFlag <> true and item.content is not null order by item.timestamp desc"),
@NamedQuery(name = "item.findThreaded",
query = "from PasteItem item where item.isPrivate <> true AND item.abuseFlag <> true and item.content is not null and item.parent is null order by item.timestamp desc"),
@NamedQuery(name = "item.findByLanguage",
query = "from PasteItem item where item.isPrivate <> true AND item.abuseFlag <> true and item.content is not null and item.type = :type order by item.timestamp desc"),
@NamedQuery(name = "item.findByLanguageThreaded",
query = "from PasteItem item where item.isPrivate <> true AND item.abuseFlag <> true and item.content is not null and item.parent is null and item.type = :type order by item.timestamp desc"),
@NamedQuery(name = "item.findByToken",
query = "from PasteItem item where item.privateToken = :token"),
@NamedQuery(name = "item.findByUser",
query = "from PasteItem item where item.isPrivate <> true AND item.abuseFlag <> true and item.content is not null and item.userToken = :token"),
@NamedQuery(name = "item.count",
query = "select count(item) from PasteItem item where item.isPrivate <> true AND item.abuseFlag <> true")
})
public class PasteItem implements Serializable {
private static final long serialVersionUID = -6467870857777145137L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ITEM_ID")
protected long id;
@Lob
@Column(name = "CONTENT")
protected String content;
@Lob
@Column(name = "HTML_CONTENT")
protected String formatedContent;
@Basic
@Column(name = "LANG_TYPE_CD")
protected String type;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CREATE_TS")
protected Date timestamp;
@Basic
@Column(name = "USER_TOKEN")
protected String userToken;
@Basic
@Column(name = "ABUSE_FLAG")
protected boolean abuseFlag;
// @Basic
// @Column(name = "CLIENT_TOKEN")
// protected String clientToken;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CLIENT_ID")
protected Client client;
@Basic
@Column(name = "PRIVATE_FLG")
protected boolean isPrivate;
@Basic
@Column(name = "PRIVATE_TOKEN", unique = true, updatable = false)
protected String privateToken;
@ManyToOne(fetch = FetchType.LAZY, optional = true)
@JoinColumn(name = "PARENT_ITEM_ID", nullable = true)
protected PasteItem parent;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "parent")
protected List<PasteItem> children;
// Lots of unannotated getters and setters...
}