Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8034919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:09:40+00:00 2026-06-05T02:09:40+00:00

I have a simple class mapped to a table. Nothing fancy, but I have

  • 0

I have a simple class mapped to a table. Nothing fancy, but I have four table columns that are not referenced in the class. This is a typical pattern, and it works everywhere else in the application. Furthermore, it was working until a small change in the table. Now, one of the four table columns not referenced in the class is being included by Hibernate, leading to a null constraint violation (the column has a default value; down the road, it will be supplied by a trigger.)

Here is the table definition (sorry about the DDL, SQL Developer won’t “copy” from a grid). All columns have “not null” constraints except modifiedby and modifieddate.

CREATE TABLE "XYZOWNER"."COMMENTM2" (
"COMMENTID" NUMBER(18,0), 
"CREATEDBY" VARCHAR2(255 CHAR) DEFAULT '{none provided}', 
"CREATEDDATE" DATE DEFAULT sysdate, 
"MODIFIEDBY" VARCHAR2(255 CHAR), 
"MODIFIEDDATE" DATE, 
"CREATEDONDATE" DATE, 
"CREATEDONTIME" DATE, 
"CREATEDBYADMIN" NUMBER(1,0) DEFAULT 0, 
"USERNAME" VARCHAR2(100 CHAR), 
"MKTPARTICIPANTID" NUMBER(18,0), 
"REFAPP" VARCHAR2(20 CHAR), 
"REFID" NUMBER(18,0), 
"TEXT" VARCHAR2(2000 CHAR)
) ;

Here is the class.

package org.midwestiso.marketapps.mect2.entities;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * This class implements the Comment entity.
 * <p>
 * Note: the database table is named CommentM2, as "comment" is a reserved word.
 */
@Entity
@Table(name = "mect2owner.commentm2")
public class Comment {
/** DB ID */
private Long commentId;
/** Created on date (midnight GMT) */
private Date createdOnDate;
/** Created on time (1970-01-01 GMT) */
private Date createdOnTime;
/** Created by admin? */
private Boolean createdByAdmin;
/** User name */
private String userName;
/** Market Participant */
private MarketParticipant mktParticipant;
/** Reference application */
private String refApp;
/** Reference application ID */
private Long refId;
/** Text */
private String text;

/**
 * Return the commentId
 * 
 * @return the commentId
 */
@Id
@SequenceGenerator(name = "sequence", sequenceName = "mect2owner.seq_commentm2")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence")
public Long getCommentId() {
    return commentId;
}

/**
 * Return the createdOnDate <br />
 * Time set to midnight GMT
 * 
 * @return the createdOnDate
 */
public Date getCreatedOnDate() {
    return createdOnDate;
}

/**
 * Return the createdOnTime <br />
 * Date set to 1970-01-01
 * 
 * @return the createdOnTime
 */
public Date getCreatedOnTime() {
    return createdOnTime;
}

/**
 * Return the createdOn date/time as a String
 * 
 * @return the createdOn date/time as a String
 */
@Transient
public String getCreatedOn() {
    final String createdOn;
    final Calendar calendar;

    // Set the calendar to market time (EST)
    calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT-5"));
    // Set the calendar to the created on date + time
    calendar.setTimeInMillis(createdOnDate.getTime() + createdOnTime.getTime());

    createdOn =
            "" + calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.MONTH) + "-"
                    + calendar.get(Calendar.DAY_OF_MONTH) + " " + calendar.get(Calendar.HOUR_OF_DAY) + ":"
                    + calendar.get(Calendar.MINUTE);

    return createdOn;
}

/**
 * Return the createdByAdmin
 * 
 * @return the createdByAdmin
 */
public Boolean getCreatedByAdmin() {
    return createdByAdmin;
}

/**
 * Return the userName
 * 
 * @return the userName
 */
@Column(name = "createdBy")
public String getUserName() {
    return userName;
}

/**
 * Return the mktParticipant
 * 
 * @return the mktParticipant
 */
@ManyToOne
@JoinColumn(name = "mktParticipantId")
public MarketParticipant getMktParticipant() {
    return mktParticipant;
}

/**
 * Return the refApp
 * 
 * @return the refApp
 */
public String getRefApp() {
    return refApp;
}

/**
 * Return the refId
 * 
 * @return the refId
 */
public Long getRefId() {
    return refId;
}

/**
 * Return the text
 * 
 * @return the text
 */
public String getText() {
    return text;
}

/**
 * Set the commentId (limited scope)
 * 
 * @param commentIdParm
 *           the commentId to set
 */
void setCommentId(final Long commentIdParm) {
    commentId = commentIdParm;
}

/**
 * Set the createdOnDate (limited scope)
 * 
 * @param createdOnDateParm
 *           the createdOnDate to set
 */
void setCreatedOnDate(final Date createdOnDateParm) {
    createdOnDate = createdOnDateParm;
}

/**
 * Set the createdOnTime (limited scope)
 * 
 * @param createdOnTimeParm
 *           the createdOnTime to set
 */
void setCreatedOnTime(final Date createdOnTimeParm) {
    createdOnTime = createdOnTimeParm;
}

/**
 * Set the created on date and time to the current date
 */
public void setCreatedOn() {
    final Date now = new Date();
    final Calendar calendar;

    // Set up a Calendar with GMT timezone and the current date
    calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    calendar.setTime(now);

    // Adjust the Calendar to midnight
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    createdOnDate = calendar.getTime();
    createdOnTime = new Date(now.getTime() - createdOnDate.getTime());
}

/**
 * Set the createdByAdmin
 * 
 * @param createdByAdminParm
 *           the createdByAdmin to set
 */
public void setCreatedByAdmin(final Boolean createdByAdminParm) {
    createdByAdmin = createdByAdminParm;
}

/**
 * Set the userName
 * 
 * @param userNameParm
 *           the userName to set
 */
public void setUserName(final String userNameParm) {
    userName = userNameParm;
}

/**
 * Set the mktParticipant
 * 
 * @param mktParticipantParm
 *           the mktParticipant to set
 */
public void setMktParticipant(final MarketParticipant mktParticipantParm) {
    mktParticipant = mktParticipantParm;
}

/**
 * Set the refApp
 * 
 * @param refAppParm
 *           the refApp to set
 */
public void setRefApp(final String refAppParm) {
    refApp = refAppParm;
}

/**
 * Set the refId
 * 
 * @param refIdParm
 *           the refId to set
 */
public void setRefId(final Long refIdParm) {
    refId = refIdParm;
}

/**
 * Set the text
 * 
 * @param textParm
 *           the text to set
 */
public void setText(final String textParm) {
    text = textParm;
}
}

Here is the Hibernate-generated SQL (createdBy is the offending column):

insert into xyzowner.commentm2 
(createdByAdmin, createdOnDate, createdOnTime, mktParticipantId, refApp, refId, text, 
createdBy, commentId) 
values (?, ?, ?, ?, ?, ?, ?, ?, ?)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:09:42+00:00Added an answer on June 5, 2026 at 2:09 am

    Now I am not an expert on Hibernate, but I believe that the reason you ran into problem this time, is because you annotated it with @Column.

    You could try to add @Generated(GenerationTime.insert), or change the @Column to include insertable = false, updatable = false (assuming you don’t want it to be included in updates either)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple table(mapped as AuthToken class), consisting of a string ('token'),
I have a simple Class Hierarchy that I am trying to get to work
I have a simple class that contains some general information about the current web
I have an simple class that I get from a webservice. public class person
I have a simple class with an attribute that can contain a list of
I have this simple class public class Position{ int x; int y; Position(int x,int
If I have a simple class setup like this: class MyClass { private string
I have a simple POJO mapped to a table using Hibernate. Which works just
I have the following django model (mapped to table 'A'): class A(models.Model): name =
I have a legacy table with composite keys that are mapped to 3 other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.