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 8151351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:21:29+00:00 2026-06-06T15:21:29+00:00

I’ve read several topics about this as well as the API and I feel

  • 0

I’ve read several topics about this as well as the API and I feel like I am on the right track; however, I must still not be understanding enough to get it working, because.. well it doesn’t work!

I have the following 2 tables: TODO and JOBTYPE

TODO table has TDTDKEY (PK) and TDJTKEY(FK?)
JOBTYPE table has JTJTKEY (PK) and JTCODE

enter image description here

As you can see Todo.tdjtkey corresponds to jobtype.jtjtkey and my goal is to retrieve the jtcode rather than the key.

The Entity classes look partially like this:

Todo.java

@Id
@Basic(optional = false)
@Column(name = "TDTDKEY")
private String primaryKey;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "TDJTKEY", insertable = true, updatable = true)
private JobType jobType;

public Todo() {
}

public Todo(String primaryKey) {
    this.primaryKey = primaryKey;
}

public String getPrimaryKey() {
    return primaryKey;
}

public void setPrimaryKey(String primaryKey) {
    this.primaryKey = primaryKey;
}

public JobType getJobType() {
    return jobType;
}

public void setJobType(JobType jobType) {
    this.jobType = jobType;
}

JobType.java

@Id
@Basic(optional = false)
@Column(name = "JTJTKEY")
private String primaryKey;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "jobType")
private Todo todo;
@Column(name = "JTCODE")
private String jobCode;

public JobType() {
}

public JobType(String primaryKey) {
    this.primaryKey = primaryKey;
}

public String getPrimaryKey() {
    return primaryKey;
}

public void setPrimaryKey(String primaryKey) {
    this.primaryKey = primaryKey;
}

public String getJobCode() {
    return jobCode;
}

public void setJobCode(String jobCode) {
    this.jobCode = jobCode;
}

So when I do a named query for Todo.findAll it gives me TDTDKEY (i.e. TD00000001) and the associated TDJTKEY CODE (i.e. PICS PGM).

Now, now that I finally got my select working, I am trying to see how I can add/edit.

So for example, if I am on TD00000001 and I want to change PROG to SUPPORT.

If I try it the normal way of sv.setJobType(txtJobType.getText()); it doesn’t work and gives me:

method setJobType in class entity.Todo cannot be applied to given types;
  required: entity.JobType
  found: java.lang.String
  reason: actual argument java.lang.String cannot be converted to entity.JobType by method invocation conversion

So that’s more or less understandable to me, but I am clueless on how I could perform an update to Todo table? Somehow I need it to find SUPPORT in JobType.java and then get the JTJTKEY of it and put it as a new TDJTKEY in the Todo.java?

Any help/hints are appreciated!

Edit: The following code works as per answer! Thanks!

String jpql = "select jobType from JobType jobType where jobType.jobCode = :code";
JobType otherJobType = WWEntityManager.entityManager.createQuery(jpql, JobType.class).setParameter("code", txtJobType.getText()).getSingleResult();

todoEntity.getJobType().removeTodo(todoEntity);
todoEntity.setJobType(otherJobType);
otherJobType.addTodo(todoEntity);

And my entity classes look like this now

Todo.java

@ManyToOne
@JoinColumn(name = "TDJTKEY", insertable = true, updatable = true)
private JobType jobType;

JobType.java

@OneToMany(targetEntity=Todo.class, mappedBy="jobType")
private Collection jobTypes;

Of course I had to add the appropriate methods for remove and add.

  • 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-06T15:21:32+00:00Added an answer on June 6, 2026 at 3:21 pm

    First of all, you have 2 TODO rows with the same job key. So, either the data are wrong, or they’re right but your association should then be ManyToOne/OneToMany instead of OneToOne/OneToOne.

    Now, regarding your question. If you want to change the code of the job of a todo, the answer is very simple:

    todo.getJobType().setJobCode("newCode");
    

    If, in fact, you want the TODO to refer to another, existing JobType (supposing the association is a ManyToOne):

    todo.getJobType().removeTodo(todo); // remove the todo from its current job type
    todo.setJobType(otherJobType); // set the new job type in todo
    otherJobType.addTodo(todo); // add the todo to its new job type
    

    Now the question is: how to get the reference to this otherJobType. If you have its ID, the answer is simple:

    JobType otherJobType = em.find(JobType.class, otherJobTypeId);
    

    If you only have its code, you’ll need to execute a query to find it. Assuming the code is unique:

    String jpql = "select jobType from JobType jobType where jobType.jobCode = :code";
    JobType otherJobType = em.createQuery(jpql, JobType.class)
                             .setParameter("code", otherJobTypeCode)
                             .getSingleResult();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I am using parse_ini_file to read the contents of a file however it is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

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.