org.seasar.doma.jdbc.JdbcException: [DOMA2022] IDプロパティのないエンティティ[LogicalDeletable]の更新や削除はできません
Last active
December 10, 2015 03:08
-
-
Save gakuzzzz/4372720 to your computer and use it in GitHub Desktop.
汎用的なDelegateのリフレクション使わない版
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.joda.time.DateTime; | |
import org.seasar.doma.Column; | |
import org.seasar.doma.Entity; | |
@Entity | |
public abstract class LogicalDeletable { | |
@Column | |
protected DateTime deletedTime; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.annotation.Nonnull; | |
import org.seasar.doma.Column; | |
import org.seasar.doma.Entity; | |
import org.seasar.doma.GeneratedValue; | |
import org.seasar.doma.GenerationType; | |
import org.seasar.doma.Id; | |
import org.seasar.doma.SequenceGenerator; | |
import org.seasar.doma.jdbc.entity.NamingType; | |
@Entity(naming = NamingType.SNAKE_UPPER_CASE) | |
public class Employee extends LogicalDeletable { | |
@Id | |
// @GeneratedValue(strategy = GenerationType.SEQUENCE) // Domainオブジェクトに@GeneratedValueつけようとすると怒られる | |
// @SequenceGenerator(sequence = "EMPLOYEE_SEQ") | |
public EmployeeId id; | |
@Column | |
public String name; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.seasar.doma.Dao; | |
import org.seasar.doma.Delegate; | |
import org.seasar.doma.Update; | |
@Dao | |
public interface LogicalDeletableDao { | |
@Update | |
int update(LogicalDeletable entity); | |
@Delegate(to = LogicalDeletableDaoDelegate.class) | |
int delete(LogicalDeletable entity); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.joda.time.DateTime; | |
import org.seasar.doma.jdbc.Config; | |
public class LogicalDeletableDaoDelegate { | |
private final Config config; | |
private final LogicalDeletableDao dao; | |
public LogicalDeletableDaoDelegate(final Config config, final LogicalDeletableDao dao) { | |
this.config = config; | |
this.dao = dao; | |
} | |
public int delete(final LogicalDeletable entity) { | |
entity.deletedTime = DateTime.now(); | |
return dao.update(entity); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.seasar.doma.Dao; | |
import org.seasar.doma.Delegate; | |
import org.seasar.doma.Insert; | |
import org.seasar.doma.Select; | |
import org.seasar.doma.Update; | |
@Dao | |
public interface EmployeeDao extends LogicalDeletableDao { | |
@Update | |
int update(Employee entity); | |
@Insert | |
int insert(Employee entity); | |
@Delegate(to = LogicalDeletableDaoDelegate.class) | |
int delete(Employee entity); | |
} |
LogicalDeletableDao
を 以下のようにすればいけるかと思ったが、
@Dao
public interface LogicalDeletableDao<T extends LogicalDeletableEntity> {
@Update
int update(T entity);
@Delegate(to = LogicalDeletableDaoDelegate.class)
int delete(T entity);
}
[DOMA4059] Daoインタフェースには型パラメータを定義できません。
というエラーで怒られる。
かといって@Dao
を付けないと
[DOMA4188] @Daoが注釈されたインタフェースは@Daoが注釈されてないインタフェース[models.shared.LogicalDeletableDao]をextendsできません。
となる。
余談だが、Domain Object型のプロパティに @GeneratedValue
を付けようとすると怒られる。
@Id
に Domain Object型が使えなくて非常につらいです……。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ありがとうございます。早速試してみました。
一点はまりましたが、上手くいきました!!
ハマったのは以下のポイントです。
Entity の型があわずに
deletedAt
にアクセスできない感じです。以下のようにすると Java Compiler がエラー吐いて落ちます^^;;;
一応、以下のようにすることで対応は可能でした。
取り急ぎご報告まで