所有属性的@Embedded Object返回错误

时间:2019-06-03 17:53:57

标签: java sql hibernate

我正在尝试按照大学老师提供给我们的架构从Active Directory中检索信息。基本上,我试图检索已嵌入一个ObjectEntity的AccountEntity对象。

数据库表

CREATE TABLE tbl_forests
(
    intCode int NOT NULL,
    strName nvarchar(20) NOT NULL,
    bolProduction bit NOT NULL,
    CONSTRAINT pk_forests PRIMARY KEY (intCode)
)
CREATE TABLE tbl_domains
(
    intForest int NOT NULL,
    strName nvarchar(20) NOT NULL
    CONSTRAINT pk_domain PRIMARY KEY (strName),
    CONSTRAINT fk_domainsforests FOREIGN KEY (intForest) REFERENCES tbl_forests(intCode)
)
CREATE TABLE tbl_objects
(
    strDomain nvarchar(20) NOT NULL,
    strCanonicalName nvarchar(255) NOT NULL,
    strCN nvarchar(255),
    objCreated datetime NOT NULL,
    objcreateTimeStamp datetime NOT NULL,
    strDescription nvarchar(MAX),
    strDisplayName nvarchar(255),
    strDistinguishedName nvarchar(255) NOT NULL,
    strHomePage nvarchar(255),
    intinstanceType int NOT NULL,
    strLastKnownParent nvarchar(MAX),
    objModified datetime,
    objmodifyTimeStamp datetime,
    strName nvarchar(255),
    strObjectCategory nvarchar(MAX),
    strObjectClass nvarchar(MAX),
    strObjectGUID nvarchar(36) NOT NULL,
    strobjectSid nvarchar(255) NOT NULL,
    strsAMAccountName nvarchar(255) NOT NULL,
    objwhenChanged datetime,
    objwhenCreated datetime NOT NULL,
    objDataDate datetime NOT NULL,
    CONSTRAINT pk_objects PRIMARY KEY (strObjectGUID),
    CONSTRAINT fk_objectssdomains FOREIGN KEY (strDomain) REFERENCES tbl_domains(strName)
)
CREATE TABLE tbl_accounts
(
    objAccountExpirationDate datetime,
    objAccountExpires datetime,
    objAccountLockoutTime datetime,
    intBadLogonCount int,
    objbadPasswordTime datetime,
    intbadPwdCount int,
    strcodePage nvarchar(MAX),
    strcountryCode nvarchar(MAX),
    objLastBadPasswordAttempt datetime,
    objlastLogoff datetime,
    objlastLogon datetime,
    objLastLogonDate datetime,
    objlastLogonTimestamp datetime,
    intlogonCount int NOT NULL,
    strObjectGUID nvarchar(36) NOT NULL,
    objPasswordLastSet datetime,
    strPrimaryGroup nvarchar(MAX) NOT NULL,
    intPrimaryGroupID int NOT NULL,
    objpwdLastSet datetime,
    intuserAccountControl int NOT NULL,
    strUserPrincipalName nvarchar(255) NOT NULL
    CONSTRAINT pk_accounts PRIMARY KEY (strObjectGUID),
    CONSTRAINT fk_accountsobjects FOREIGN KEY (strObjectGUID) REFERENCES tbl_objects(strObjectGUID)
)

Java对象

@Entity
@Table(name = "tbl_forests")
public class ForestEntity
{
    @Id
    @Column(name = "intCode")
    private Integer intCode;
    private String strName;
    private Boolean bolProduction;
}
@Entity
@Table(name = "tbl_domains")
public class DomainEntity
{
    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "intForest", referencedColumnName = "intCode")
    private ForestEntity objForest;
    @Id
    @Column(name = "strName")
    private String strName;
}
@Entity
@Table(name = "tbl_objects")
public class ObjectEntity
{
    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "strDomain", referencedColumnName = "strName")
    private DomainEntity objDomain;
    private String strCanonicalName;
    private String strCN;
    private Timestamp objCreated;
    private Timestamp objcreateTimeStamp;
    private String strDescription;
    private String strDisplayName;
    private String strDistinguishedName;
    private String strHomePage;
    private Integer intinstanceType;
    private String strLastKnownParent;
    private Timestamp objModified;
    private Timestamp objmodifyTimeStamp;
    private String strName;
    private String strObjectCategory;
    private String strObjectClass;
    @Id
    @Column(name = "strObjectGUID")
    private String strObjectGUID;
    private String strobjectSid;
    private String strsAMAccountName;
    private Timestamp objwhenChanged;
    private Timestamp objwhenCreated;
}
@Entity
@Table(name = "tbl_accounts")
public class AccountEntity
{
    private Timestamp objAccountExpirationDate;
    private Timestamp objAccountExpires;
    private Timestamp objAccountLockoutTime;
    private Integer intBadLogonCount;
    private Timestamp objbadPasswordTime;
    private Integer intbadPwdCount;
    private String strcodePage;
    private String strcountryCode;
    private Timestamp objLastBadPasswordAttempt;
    private Timestamp objlastLogoff;
    private Timestamp objlastLogon;
    private Timestamp objLastLogonDate;
    private Timestamp objlastLogonTimestamp;
    private Integer intlogonCount;
    @Id
    @Column(name = "strObjectGUID")
    private String strObjectGUID;
    @Embedded
    private ObjectEntity objObject;
    private Timestamp objPasswordLastSet;
    private String strPrimaryGroup;
    private Integer intPrimaryGroupID;
    private Timestamp objpwdLastSet;
    private Integer intuserAccountControl;
    private String strUserPrincipalName;
}
public static void main(String[] args) throws Exception
{
    Session objSession;
    objSession = this.objSessionFactory.openSession();
    try
    {
        List<AccountEntity> colValues = (List<AccountEntity>) objSession.createQuery("FROM AccountEntity").list();
    }
    catch (Exception objException)
    {
    }
    objSession.close();
}

我收到的错误是

javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
WARN  org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 207, SQLState: S0001
ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Invalid column name 'strSAMAccountName'.

我尝试删除此列,但在属性列表中的下一个列出现相同的错误

不知道这是否有助于识别问题,但我是否可以更改

List<AccountEntity> colValues = (List<AccountEntity>) objSession.createQuery("FROM AccountEntity").list();

 List<ObjetEntity> colValues = (List<ObjectEntity>) objSession.createQuery("FROM ObjectEntity").list();

我恢复了ObjectEntity。仅当我尝试恢复AccountEntity且仅在ObjectEntity属性上显示无效列名错误时,才会出现此问题

0 个答案:

没有答案