私は、エンティティ持っている:私はステートレスEJBを作成しているHibernateのアップデートのみ選択された列の代わりに、すべての変更されたフィールド
@Entity
@Table(name = "my_dto")
public class MyDto implements Serializable
{
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
private String id;
private String displayName;
private String remark;
@Column(name = "BACKGROUND")
private Integer backgroundColorInt;
@Column(name = "FOREGROUND")
private Integer foregroundColorInt;
private boolean isBold;
private boolean isItalic;
private boolean isUnderlined;
@Column(name = "ISBLINKINGACTIVE")
private Boolean blinkingActive;
@Column(name = "ISBLINKINGBOLD")
private Boolean blinkingBold;
@Column(name = "ISBLINKINGITALIC")
private Boolean blinkingItalic;
@Column(name = "ISBLINKINGUNDERLINED")
private Boolean blinkingUnderlined;
@Column(name = "BLINKINGBACKGROUND")
private Integer blinkingBackColorInt;
@Column(name = "BLINKINGFOREGROUND")
private Integer blinkingForeColorInt;
@Column
private String createdBy;
@Column
private Date createDat;
@Column
private String changedBy;
@Column
private Date changeDat;
@Version
private int version;
@Transient
private Map< String, Object > appearanceConfig = null;
@PostLoad
public void copyMyDto2AppearanceConfig()
{
if(appearanceConfig == null)
{
appearanceConfig = new HashMap< String, Object >();
}
appearanceConfig.put(BACKGROUND_COLOR, backgroundColorInt);
appearanceConfig.put(FOREGROUND_COLOR, foregroundColorInt);
appearanceConfig.put(FONT_STYLE, getFontStyle());
appearanceConfig.put(IS_BLINKING_ACTIVE, blinkingActive);
HashMap< String, Object > blinkingConf = new HashMap< String, Object >();
blinkingConf.put(FOREGROUND_COLOR, blinkingForeColorInt);
blinkingConf.put(BACKGROUND_COLOR, blinkingBackColorInt);
blinkingConf.put(FONT_STYLE, getBlinkingFontStyle());
appearanceConfig.put(BLINKING_CONFIGURATION, blinkingConf);
}
@PreUpdate
public void copyAppearanceConfig2MyDto()
{
setForegroundColor((Integer)appearanceConfig.get(FOREGROUND_COLOR));
setBackgroundColor((Integer)appearanceConfig.get(BACKGROUND_COLOR));
setFontStyle((FontStyle[])appearanceConfig.get(FONT_STYLE));
setBlinkingActive(Boolean.TRUE.equals(appearanceConfig.get(IS_BLINKING_ACTIVE)));
Map< String, Object > blinkingConf =
(Map< String, Object >)appearanceConfig.get(BLINKING_CONFIGURATION);
if(blinkingConf != null)
{
setBlinkingFontStyle((FontStyle[])blinkingConf.get(FONT_STYLE));
setBlinkingForegroundColor((Integer)blinkingConf.get(FOREGROUND_COLOR));
setBlinkingBackgroundColor((Integer)blinkingConf.get(BACKGROUND_COLOR));
}
else
{
setBlinkingFontStyle(null);
setBlinkingForegroundColor((Integer)null);
setBlinkingBackgroundColor((Integer)null);
}
}
// some standard getters and setters...
}
は、EARのパッケージにそれを詰め、JBossサーバ(Wildfly-10)にそれを展開しました。私は今では全く問題なくデータベースからMyDto
を作成/削除することができます。私にとって心配なのは、更新操作です。次のように更新のEJBの実装は次のとおりです。
@Stateless
@Remote(MyDtoStorageServiceIf.class)
public class MyDtoStorageService implements MyDtoStorageServiceIf
{
@PersistenceContext(unitName = "DS_MY_DTO", name = "DS_MY_DTO")
protected EntityManager entityManager;
@Override
public MyDto update(MyDto aMyDto)
{
MyDto myDto = entityManager.merge(aMyDto);
entityManager.flush();
return myDto;
}
// other EJB methods, e.g. persisting new MyDto object, deleting selected MyDto from database etc.
}
私が選択した行を更新しようとすると、それはaMyDto
のいくつかの他の分野にもなっているにもかかわらず、唯一のdisplayName
とremark
フィールドがデータベースで更新されて判明します変更されました。その理由は、MyDto
クラスの@PreUpdateメソッドと@PostLoadメソッドにある可能性はありますか?私はアイデアが不足しているので、この奇妙な行動の理由を指摘してもらいたいと思います。何が欠けているのでしょうか?何が問題ですか?