Ошибка SQL при сохранении экземпляра в Hibernate

1

Когда я пытаюсь сохранить экземпляр, я получаю эту странную ошибку:

WARN [15:06:27,917] JDBCExceptionReporter - SQL Error: 20000, SQLState: 42X04
ERROR[15:06:27,917] JDBCExceptionReporter - Column 'ad0b8d24-f596-47cb-9d79-06a3c9c1de26' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE  statement then 'ad0b8d24-f596-47cb-9d79-06a3c9c1de26' is not a column in the target table.

Строка не добавляется в базу данных. Похоже, он пытается использовать script_id (uuid) в качестве имени столбца. Но почему?

Я использую этот объект доступа к данным:

public interface ScenarioDao extends GenericDao<Scenario, String> {
    public List<Scenario> getScenariosWhereOwner(Person owner);
    public List<Scenario> getScenariosWhereOwner(Person person, int LIMIT);
...
}

public interface GenericDao <T, PK extends Serializable>{
  public PK create(T newInstance) {
    PK primaryKey = (PK) getHibernateTemplate().save(newInstance);
    return primaryKey;
}
}

POJO:

@Entity
@Table(name = "SCENARIO")
@XmlRootElement
public class Scenario implements Serializable, Comparable<Scenario> {

    private static final long serialVersionUID = -6608175331606366993L;

    private String scenarioId;
    private Person person;
    private ResearchGroup researchGroup;
    private String title;
    private int scenarioLength;
    private boolean privateScenario;
    private String description;
    private String scenarioName;
    private String mimetype;
    private Set<History> histories = new HashSet<History>(0);
    private Set<Experiment> experiments = new HashSet<Experiment>(0);
    private boolean userMemberOfGroup;
    private Blob scenarioFile;
    private String group;
    private Boolean availableFile;

    private InputStream fileContentStream;

    @Transient
    public boolean isUserMemberOfGroup() {
        return userMemberOfGroup;
    }

    public void setUserMemberOfGroup(boolean userMemberOfGroup) {
        this.userMemberOfGroup = userMemberOfGroup;
    }

    @Transient
    public String getGroup() {
        return group;
    }

    public void setGroup(String group) {
        this.group = group;
    }

    @Transient
    public Boolean getAvailableFile() {
        return availableFile;
    }

    public void setAvailableFile(Boolean availableFile) {
        this.availableFile = availableFile;
    }

    public Scenario() {
    }

    public Scenario(Person person, ResearchGroup researchGroup) {
        this.person = person;
        this.researchGroup = researchGroup;
    }

    public Scenario(Person person, ResearchGroup researchGroup, String title,
            int scenarioLength, boolean privateScenario, String description,
            String scenarioName, String mimetype, Set<History> histories,
            Set<Experiment> experiments) {
        this.person = person;
        this.researchGroup = researchGroup;
        this.title = title;
        this.scenarioLength = scenarioLength;
        this.privateScenario = privateScenario;
        this.description = description;
        this.scenarioName = scenarioName;
        this.mimetype = mimetype;
        this.histories = histories;
        this.experiments = experiments;
    }

    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid2")
    @Column(name = "SCENARIO_ID", nullable = false, length = 36, scale = 0)
    public String getScenarioId() {
        return this.scenarioId;
    }

    public void setScenarioId(String scenarioId) {
        this.scenarioId = scenarioId;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "OWNER_ID", nullable = false)
    public Person getPerson() {
        return this.person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "RESEARCH_GROUP_ID", nullable = false)
    public ResearchGroup getResearchGroup() {
        return this.researchGroup;
    }

    public void setResearchGroup(ResearchGroup researchGroup) {
        this.researchGroup = researchGroup;
    }

    @Column(name = "TITLE", unique = true)
    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Column(name = "SCENARIO_LENGTH", precision = 22, scale = 0)
    public int getScenarioLength() {
        return this.scenarioLength;
    }

    public void setScenarioLength(int scenarioLength) {
        this.scenarioLength = scenarioLength;
    }

    @Column(name = "PRIVATE", precision = 1, scale = 0)
    public boolean isPrivateScenario() {
        return this.privateScenario;
    }

    public void setPrivateScenario(boolean privateScenario) {
        this.privateScenario = privateScenario;
    }

    @Lob
    @Type(type = "org.hibernate.type.TextType")
    @Column(name = "DESCRIPTION")
    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column(name = "SCENARIO_NAME")
    public String getScenarioName() {
        return this.scenarioName;
    }

    public void setScenarioName(String scenarioName) {
        this.scenarioName = scenarioName;
    }

    @Column(name = "MIMETYPE")
    public String getMimetype() {
        return this.mimetype;
    }

    public void setMimetype(String mimetype) {
        this.mimetype = mimetype;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "scenario")
    public Set<History> getHistories() {
        return this.histories;
    }

    public void setHistories(Set<History> histories) {
        this.histories = histories;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "scenario")
    public Set<Experiment> getExperiments() {
        return this.experiments;
    }

    public void setExperiments(Set<Experiment> experiments) {
        this.experiments = experiments;
    }

    @XmlJavaTypeAdapter(BlobSerializer.class)
    @Basic(fetch = FetchType.LAZY)
    @Lob
    @Column(name = "SCENARIO_FILE", nullable = true)
    public Blob getScenarioFile() {
        return this.scenarioFile;
    }

    public void setScenarioFile(Blob scenarioFile) {
        this.scenarioFile = scenarioFile;
    }

    @Override
    public int compareTo(Scenario scen) {
        return this.title.compareTo(scen.getTitle());
    }

    public void setFileContentStream(InputStream inputStream) {
        this.fileContentStream = inputStream;
    }

    @Transient
    public InputStream getFileContentStream() {
        return fileContentStream;
    }
}

Я пытаюсь создать его с помощью этого кода:

 scenario = new Scenario();
            scenario.setPrivateScenario(some boolean);
            scenario.setScenarioLength(some int);
            scenario.setDescription(some string);
            scenario.setTitle(some string);
            scenario.setResearchGroup(some ResearchGroup);
            scenario.setPerson(some Person);

Все эти параметры установлены правильно. Я также использую GenericDao с другими объектами без ошибок. Вот инструкция insert, сгенерированная спящим:

DEBUG[16:07:25,132] SQL - insert into SCENARIO (DESCRIPTION, MIMETYPE, OWNER_ID, PRIVATE, RESEARCH_GROUP_ID, SCENARIO_FILE, SCENARIO_LENGTH, SCENARIO_NAME, TITLE, SCENARIO_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
TRACE[16:07:25,153] BasicBinder - binding parameter [1] as [LONGVARCHAR] - newscenariodescription
TRACE[16:07:25,153] BasicBinder - binding parameter [2] as [VARCHAR] - <null>
TRACE[16:07:25,153] BasicBinder - binding parameter [3] as [VARCHAR] - 9e87924e-3a14-4f82-ad57-c191ead873b5
TRACE[16:07:25,153] BasicBinder - binding parameter [4] as [BIT] - false
TRACE[16:07:25,154] BasicBinder - binding parameter [5] as [VARCHAR] - b399f04f-92a7-427c-9af5-f90055cb1ddc
TRACE[16:07:25,154] BasicBinder - binding parameter [6] as [BLOB] - <null>
TRACE[16:07:25,154] BasicBinder - binding parameter [7] as [INTEGER] - 5
TRACE[16:07:25,154] BasicBinder - binding parameter [8] as [VARCHAR] - <null>
TRACE[16:07:25,154] BasicBinder - binding parameter [9] as [VARCHAR] - newscenario
TRACE[16:07:25,154] BasicBinder - binding parameter [10] as [VARCHAR] - 2d71bcd2-756e-4ffd-82b0-9649d7f05e0b
WARN [16:07:25,180] JDBCExceptionReporter - SQL Error: 20000, SQLState: 38000
ERROR[16:07:25,180] JDBCExceptionReporter - The exception 'java.sql.SQLException: Column '2d71bcd2-756e-4ffd-82b0-9649d7f05e0b' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE  statement then '2d71bcd2-756e-4ffd-82b0-9649d7f05e0b' is not a column in the target table.' was thrown while evaluating an expression.

Когда я пытаюсь выполнить:

String query = "insert into SCENARIO (DESCRIPTION, MIMETYPE, OWNER_ID, PRIVATE, RESEARCH_GROUP_ID, FILE_CONTENT, SCENARIO_LENGTH, SCENARIO_NAME, TITLE, SCENARIO_ID) values ('newscenariodescription', NULL, '9e87924e-3a14-4f82-ad57-c191ead873b5', 0, 'b399f04f-92a7-427c-9af5-f90055cb1ddc', NULL, 5, NULL, 'text', '2d71bcd2-756e-4ffd-82b0-9649d7f205e0b')";

session.createSQLQuery(query).executeUpdate();

Я получаю такую же ошибку.

Когда я пытаюсь выполнить запрос напрямую, я получаю очень странную ошибку:

SQL Error [20000] [38000]: The exception 'java.lang.NoClassDefFoundError: org/jumpmind/symmetric/db/derby/DerbyFunctions' was thrown while evaluating an expression.
SQL Error [XJ001]: Java exception: 'org/jumpmind/symmetric/db/derby/DerbyFunctions: java.lang.NoClassDefFoundError'.
  The exception 'java.lang.NoClassDefFoundError: org/jumpmind/symmetric/db/derby/DerbyFunctions' was thrown while evaluating an expression.
    The exception 'java.lang.NoClassDefFoundError: org/jumpmind/symmetric/db/derby/DerbyFunctions' was thrown while evaluating an expression.
      Java exception: 'org/jumpmind/symmetric/db/derby/DerbyFunctions: java.lang.NoClassDefFoundError'.
        org/jumpmind/symmetric/db/derby/DerbyFunctions
  • 0
    Можете ли вы включить ведение журнала SQL в Hibernate и проверить сгенерированный оператор вставки?
  • 0
    Готово. Я редактировал вопрос.
Показать ещё 5 комментариев
Теги:
hibernate

1 ответ

0
Лучший ответ

Я забыл установить capture_big_lobs в таблице триггеров. Изменение значения до 1 проблемы. Однако, если столбец равен NULL, тогда SymmetricDS будет генерировать исключение Null Pointer. Я использую 3.5.10, поэтому, возможно, он решил в более новых версиях.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню