How can I use JMix to do an upsert?

Please help Jmix team and community members to answer your questions:

  • Provide your Jmix framework and Studio versions. Use Welcome screen in Studio to copy versions.
    Jmix version: 2.5.0
    Jmix Studio Plugin Version: 2.5.0-243
    IntelliJ version: IntelliJ IDEA 2024.3.5 (Ultimate Edition)

I want to create a company table. The company is a ONE record table.

On Insert, it would NOT show View, it would show EDIT.
If the record exists, DO NOT allow insert, only allow edit 1 record.

On EDIT, select the first record and then allow first record to be edited.

On Delete, disable delete.

How would I do that in Jmix?

Hi
Just disable the create and remove button.
If you have a problem to do so, provide a small project and I can do that for you.
Regards
Felix

How do I send a small project… is this under community support?

Create a project with this one company and zip it.

grafik

how do I send it? …

URL:

any ideas how to make an upsert?

I checked JMix AI it didn’t give any useful info, and the forum and only 1 result…

You can just drop it here
PayWindowPayroll_Felix.zip (1.0 MB)

As you want to have a company shown fixed, I did change the id to an Integer so you can easily create a record with the ID 1 which will be shown and you will be able to edit from the menu.

Let me know, if this is what you are looking for :wink:

Regards
Felix

I’d like to ask…

  1. Can you change your demo to use a UDID?

  2. When there’s no data it crashes instead of create new record.
    How would I fix that? There’s only tutorials for Upsert for MongoDB…

  3. If there is no record, how would I use JMIX to automatically create a record or upsert?

Hi Roma
Sorry for the late reply; I was yesterday travelling.

2+3) I did adapt the program, so it creates now one record, if he does not exist

public class CompanyDetailView extends StandardDetailView<Company>
{
	@Autowired
	private DataManager dataManager;

	@Subscribe
	public void onInit(final InitEvent event)
	{
		Company company = dataManager.create(Company.class);
		try {
			dataManager.load(Company.class)
					.id(1)
					.one();
		} catch (NoResultException e) {
			//  company does not exist, create one
			company.setId(1);
			company.setCompany("new Company created");
			dataManager.save(company);
		}
	}

}
  1. I can change the program easily to use a UUID. BUT
    → in menu.xml you have to tell the application, which record to show
        <item view="Company.detail" title="Company">
            <routeParameters>
                <parameter name="id" value="1"/>
            </routeParameters>
        </item>

you see the parameter 1

If you use an UUID, this UUID will be different every time you or the system create a new record.

If you do not mention the parameter and just show the first record you find, this will not be reliable, as there might be more then one record

Later you want to make something with this entity, where you will have to pass the paramter for the id.

As you see, you will face a lot of problems and it is easier to handle a fix record id ( which can be anything you wish, even a string “paymentID”).

Still want a sample with UUID ?

Regards

Felix

PayWindowPayroll.zip (1.0 MB)