spring-data-jpa insert an entire entity
<p>I'm new to spring-data-jpa and I've been doing just fine with reading records out of a database but now I would like to insert records. I would like to follow my same pattern of using the repository class along with a query to do the insertion. Is there a way similar to this post <a href="https://stackoverflow.com/a/24848086/3299397">https://stackoverflow.com/a/24848086/3299397</a> where I can insert a record but instead of explicitly specifying each value I simply pass to the function an entity object and insert the entire object? Here is what I have so far.</p>

<p><strong>Entity Class:</strong></p>

<pre><code>package blah.blah.blah;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "MESSAGE")
public class Message implements Serializable {

@Id
// @GeneratedValue(generator = "system-uuid")
// @GenericGenerator(name = "system-uuid", strategy = "uuid")
@Column(name = "MESSAGE_GUID")
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
private String messageGuid;

@Column(name = "MESSAGE_TYPE_CD")
private Long messageTypeCd;

@Column(name = "SENDER_GUID")
private String SenderGuid;

@Column(name = "MESSAGE_TITLE")
private String messageTitle;

@Column(name = "MESSAGE_STATUS_CD")
private Long messageStatusCd;

@Column(name = "ACTIVATED_DT")
private Date activatedDt;

@Column(name = "DEACTIVATED_DT")
private Date deactivatedDt;

@Column(name = "CREATE_BY")
private String createBy;

@Column(name = "CREATE_DT")
private Date createDt;

@Column(name = "UPDATE_BY")
private String updateBy;

@Column(name = "UPDATE_DT")
private Date updateDt;

// required by JPA
public Message() {
}

@SuppressWarnings("all")
public Message(
        String messageGuid,
        Long messageTypeCd,
        String SenderGuid,
        String messageTitle,
        Long messageStatusCd,
        Date activatedDt,
        Date deactivatedDt,
        String createBy,
        Date createDt,
        String updateBy,
        Date updateDt) {
    super();
    this.messageGuid = messageGuid;
    this.messageTypeCd = messageTypeCd;
    this.SenderGuid = SenderGuid;
    this.messageTitle = messageTitle;
    this.messageStatusCd = messageStatusCd;
    this.activatedDt = activatedDt;
    this.deactivatedDt = deactivatedDt;
    this.createBy = createBy;
    this.createDt = createDt;
    this.updateBy = updateBy;
    this.updateDt = updateDt;
}

public String getMessageGuid() {
    return messageGuid;
}

public void setMessageGuid(String messageGuid) {
    this.messageGuid = messageGuid;
}

public Long getMessageTypeCd() {
    return messageTypeCd;
}

public void setMessageTypeCd(Long messageTypeCd) {
    this.messageTypeCd = messageTypeCd;
}

public String getSenderGuid() {
    return SenderGuid;
}

public void setSenderGuid(String senderGuid) {
    SenderGuid = senderGuid;
}

public String getMessageTitle() {
    return messageTitle;
}

public void setMessageTitle(String messageTitle) {
    this.messageTitle = messageTitle;
}

public Long getMessageStatusCd() {
    return messageStatusCd;
}

public void setMessageStatusCd(Long messageStatusCd) {
    this.messageStatusCd = messageStatusCd;
}

public Date getActivatedDt() {
    return activatedDt;
}

public void setActivatedDt(Date activatedDt) {
    this.activatedDt = activatedDt;
}

public Date getDeactivatedDt() {
    return deactivatedDt;
}

public void setDeactivatedDt(Date deactivatedDt) {
    this.deactivatedDt = deactivatedDt;
}

public String getCreateBy() {
    return createBy;
}

public void setCreateBy(String createBy) {
    this.createBy = createBy;
}

public Date getCreateDt() {
    return createDt;
}

public void setCreateDt(Date createDt) {
    this.createDt = createDt;
}

public String getUpdateBy() {
    return updateBy;
}

public void setUpdateBy(String updateBy) {
    this.updateBy = updateBy;
}

public Date getUpdateDt() {
    return updateDt;
}

public void setUpdateDt(Date updateDt) {
    this.updateDt = updateDt;
}

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((SenderGuid == null) ? 0 : SenderGuid.hashCode());
    result = prime * result + ((activatedDt == null) ? 0 : activatedDt.hashCode());
    result = prime * result + ((createBy == null) ? 0 : createBy.hashCode());
    result = prime * result + ((createDt == null) ? 0 : createDt.hashCode());
    result = prime * result + ((deactivatedDt == null) ? 0 : deactivatedDt.hashCode());
    result = prime * result + ((messageGuid == null) ? 0 : messageGuid.hashCode());
    result = prime * result + ((messageStatusCd == null) ? 0 : messageStatusCd.hashCode());
    result = prime * result + ((messageTitle == null) ? 0 : messageTitle.hashCode());
    result = prime * result + ((messageTypeCd == null) ? 0 : messageTypeCd.hashCode());
    result = prime * result + ((updateBy == null) ? 0 : updateBy.hashCode());
    result = prime * result + ((updateDt == null) ? 0 : updateDt.hashCode());
    return result;
}

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    Message other = (Message) obj;
    if (SenderGuid == null) {
        if (other.SenderGuid != null)
            return false;
    } else if (!SenderGuid.equals(other.SenderGuid))
        return false;
    if (activatedDt == null) {
        if (other.activatedDt != null)
            return false;
    } else if (!activatedDt.equals(other.activatedDt))
        return false;
    if (createBy == null) {
        if (other.createBy != null)
            return false;
    } else if (!createBy.equals(other.createBy))
        return false;
    if (createDt == null) {
        if (other.createDt != null)
            return false;
    } else if (!createDt.equals(other.createDt))
        return false;
    if (deactivatedDt == null) {
        if (other.deactivatedDt != null)
            return false;
    } else if (!deactivatedDt.equals(other.deactivatedDt))
        return false;
    if (messageGuid == null) {
        if (other.messageGuid != null)
            return false;
    } else if (!messageGuid.equals(other.messageGuid))
        return false;
    if (messageStatusCd == null) {
        if (other.messageStatusCd != null)
            return false;
    } else if (!messageStatusCd.equals(other.messageStatusCd))
        return false;
    if (messageTitle == null) {
        if (other.messageTitle != null)
            return false;
    } else if (!messageTitle.equals(other.messageTitle))
        return false;
    if (messageTypeCd == null) {
        if (other.messageTypeCd != null)
            return false;
    } else if (!messageTypeCd.equals(other.messageTypeCd))
        return false;
    if (updateBy == null) {
        if (other.updateBy != null)
            return false;
    } else if (!updateBy.equals(other.updateBy))
        return false;
    if (updateDt == null) {
        if (other.updateDt != null)
            return false;
    } else if (!updateDt.equals(other.updateDt))
        return false;
    return true;
}

@Override
public String toString() {
    return "Message [messageGuid=" + messageGuid + ", messageTypeCd=" + messageTypeCd + ", SenderGuid="
            + SenderGuid + ", messageTitle=" + messageTitle + ", messageStatusCd=" + messageStatusCd
            + ", activatedDt=" + activatedDt + ", deactivatedDt=" + deactivatedDt + ", createBy=" + createBy
            + ", createDt=" + createDt + ", updateBy=" + updateBy + ", updateDt=" + updateDt + "]";
}
</code></pre>

<p>}</p>

<p><strong>Repository Class:</strong></p>

<pre><code>package blah.blah.blah;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface MessageRepository extends JpaRepository&lt;Message, String&gt; {

@Query("SELECT "
        + "m "
        + "FROM Message m "
        + "WHERE messageGuid = :messageGuid")
List&lt;Message&gt; findByMessageGuid(@Param("messageGuid") String messageGuid);

// THIS DOES NOT WORK!
// @Query("INSERT "
// + "INTO Message")
// void insertMessage(@Param("myMessage") Message myMessage);

}
</code></pre>

<p><strong>Service Class:</strong></p>

<pre><code>package blah.blah.blah;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MessageServiceImpl implements MessageService {

private static final Logger log = LoggerFactory.getLogger(MessageServiceImpl.class);

@Autowired
private MessageRepository messageRepository;

@Override
public void getMessage(String messageGuid) {
    List&lt;Message&gt; messageList = messageRepository.findByMessageGuid(messageGuid);
    for (Message message : messageList)
        log.info("\n\n" + message.toString() + "\n\n");
}
</code></pre>

<p><strong>Component Class:</strong></p>

<pre><code>@Component
public class MessageComponentThingy {

@Autowired
MessageService messageService;

  public void thisIsALongExample() {

    messageService.getMessage("34A02DCF520F0831E053870910ACED7A");
  }
}
</code></pre>

<p><strong>This works for me when I want to read a record from the database...</strong></p>

<p>Update Note: Please note that I am not necessarily concerned with doing 'Native Queries' I would just like to keep the same general pattern as what is shown in my Repository class. I would not reject an answer that uses a Native Query though. It honestly doesn't matter to me.</p>