java – Primefaces passing child in OneToMany relation in f:param

Is there a way to pass the whole List<> as f:param?

I have two databases connected with bidirectional OneToMany/ManyToOne relation. In first I have elements and their properties, except names, it is connected by id with second database where are names in different languages (every language has its own id.

I also have two pages. On first I search in the first database for elements that meet the criteria. Results are displayed in the datatable, with edit button in last column.

When you click on edit button in the row, it sends you on second page, where properties of that element from both databases should be displayed.

With f:param I can send id to other page, but on page load value of id isn’t yet set and therefore I can’t load values from second database (I get nullpointerexception). If i set id as static. It loads, but always the same.

I use postgresql, primefaces. If I forgot to mention something, please let me know.

My code:

SmPestEditable.xhtml:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">
<f:metadata>
    <f:viewParam name="id" value="#{smPestsEditable.id}" />
    <f:viewParam name="code" value="#{smPestsEditable.code}" />
    <f:viewParam name="lname" value="#{smPestsEditable.latinName}" />
    <f:viewParam name="irecog" value="#{smPestsEditable.imgRecognition}" />
    <f:viewAction action="#{smPestsEditable.onload}" />
</f:metadata>

<h:messages />
<h:head></h:head>
<h:body>
<style type="text/css">
    .ui-row-editor .ui-row-editor-pencil {
        margin-left:8px;
    }
</style>
    <h:form id="pestsListEdit">
        <p:growl id="msgs" showDetail="true" />

        <p:panel id="SearchPest" header="EDIT PEST" toggleable="true"
            closable="true" toggleSpeed="500" closeSpeed="500" widgetVar="panel"
            style="margin-bottom:20px">

            <p:panelGrid columns="2">

                <h:outputLabel for="Id" value="Id" />
                <h:outputText  value="#{request.getParameter('id')}"/>
                <h:outputLabel for="slo" value="lo" />
                <h:outputText  value="#{request.getParameter('id')}"/>
                <h:outputLabel for="Code" value="Code" />
                <p:inputText id="Code" value="#{smPestsEditable.code}" label="Code" />                          
                <h:outputLabel for="lnme" value="Latin Name" />
                <p:inputText id="LatinName" value="#{smPestsEditable.latinName}" label="latin" />                           

                    
                <f:facet name="footer">
                    <p:commandButton value="CHECK"
                        actionListener = "#{smPestsEditable.saveButton}"            
                        action = "SmPestsList?faces-redirect-true" />
                    <p:linkButton outcome="SmPestsList" value="CLOSE"
                        style="margin-right:20px;">
                    </p:linkButton>
                </f:facet>
            </p:panelGrid>

        </p:panel>
        <p:dataTable var="ime" value="#{smPestsEditable.imena}">
            <p:column headerText="ID PEST NAME">
                <h:outputText value="#{ime.idPestName}" />
            </p:column>
            <p:column headerText="LANGUAGE">
                <h:outputText value="Srpski"
                    rendered="#{ime.idLanguage eq 12}" />
                <h:outputText value="Français"
                    rendered="#{ime.idLanguage eq 13}" />
                <h:outputText value="Italiano"
                    rendered="#{ime.idLanguage eq 8}" />
                <h:outputText value="English"
                    rendered="#{ime.idLanguage eq 4}" />
                <h:outputText value="Português"
                    rendered="#{ime.idLanguage eq 9}" />
                <h:outputText value="Deutsch"
                    rendered="#{ime.idLanguage eq 11}" />
                <h:outputText value="Magyar"
                    rendered="#{ime.idLanguage eq 10}" />
                <h:outputText value="Português"
                    rendered="#{ime.idLanguage eq 14}" />
                <h:outputText value="Yкраїнський"
                    rendered="#{ime.idLanguage eq 15}" />
            </p:column>
            <p:column headerText="DISPLAY NAME">
                <p:inplace id="name">
                    <p:inputText value="#{ime.name}" label="Name" />
                </p:inplace>
            </p:column>
        </p:dataTable>



    </h:form>
</h:body>
</html>

SmPestEditable.java:

package si.david;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.annotation.ManagedProperty;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityResult;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.FieldResult;
import javax.persistence.Query;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.TypedQuery;

import si.david.SmPests;
import si.david.SmPestsNames;

import org.hibernate.annotations.CreationTimestamp;
import org.junit.Before;
import org.primefaces.event.RowEditEvent;

    @Named(value="smPestsEditable")
    @RequestScoped
    public class SmPestsEditable {
        
        
    private List<SmPestsNames> pests = new ArrayList<SmPestsNames>();
    private EntityManager em =null;
    private EntityManagerFactory emf = Persistence.createEntityManagerFactory("tvTutorialPU");
    private int stevilka;
    private int id;
    private int idPest=55;
    private String sloName;
    
    SmPests zuzek1=loadPestById(idPest);
    private String code = zuzek1.getCode();
    private String oldCode = code;

    private String latinName = zuzek1.getLatinName();
    private String oldLatinName = latinName;
    private String refLink = zuzek1.getRefLink();
    private String oldRefLink = refLink;
    private Integer imgRecognition = zuzek1.getImgRecognition();
    private Integer oldImgRecognition = imgRecognition;
    private Integer hideScore = zuzek1.getHideScore();
    private Integer oldHideScore = hideScore;
    private Integer recognitionModel = zuzek1.getRecognitionModel();
    private Integer oldRecognitionModel = recognitionModel;
    private Double alarmThresholdUp = zuzek1.getAlarmThresholdUp();
    private Double oldAlarmThresholdUp = alarmThresholdUp;
    private Double alarmThresholdLow = zuzek1.getAlarmThresholdLow();
    private Double oldAlarmThresholdLow = alarmThresholdLow;
    List<SmPestsNames> imena = zuzek1.getSmPestsNames();    
    private Long idPestName;
    private int idLanguage;
    private String name;
    private LocalDateTime dInsert;
    private Long idInserter;
    private LocalDateTime dUpdate;
    private Long idUpdater;
    SmPests zuzek;
    
    
    public void onload() {
        try  {
            System.out.println(" ONLOAD: id "+id);
            System.out.println(" idpest "+idPest);
            }  catch (Exception e)   {
                System.out.println(" Can’t find  id!");
            }           
    }
    public void saveButton() {
        System.out.println("SAVE button");  
        try  {
            pestsNames(id);
            System.out.println("Sprintano pestnames(id)");
            
        }  catch (Exception e)   {
            System.out.println("Ujej!");
        }
    }

    public void pestsNames(int id) {
        EntityManager em =null;
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("tvTutorialPU");
        em = emf.createEntityManager();
        SmPests zuzek = em.find(SmPests.class,id);
        try  {
            List<SmPestsNames> imena = zuzek.getSmPestsNames(); 
            for(SmPestsNames s : imena) {
                System.out.print(s.getIdPestName());
                System.out.print(" | "+s.getIdLanguage());
                System.out.println(" | "+s.getName());}
        }  catch (Exception e)   {
            System.out.println("Ujej!");
        }
    }
    
    private SmPests loadPestById(int id) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("tvTutorialPU");
        EntityManager em = emf.createEntityManager();
        SmPests zuzek = em.find(SmPests.class, id);
        return zuzek;
    }
}

SmPestList.xhtml:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<style type="text/css">
    .ui-row-editor .ui-row-editor-pencil {
        margin-left:8px;
    }
</style>
    <h:form id="pestsList">
        <p:growl id="msgs" showDetail="true" />

        <p:panel id="SearchPest" header="Search for pests" toggleable="true"
            closable="true" toggleSpeed="500" closeSpeed="500" widgetVar="panel"
            style="margin-bottom:20px">

            <p:panelGrid columns="2">

                <h:outputLabel for="Code" value="Code" />
                <p:inputText id="Code" value="#{smPestsList.code}" label="Code" />
                <h:outputLabel for="Latin" value="Latin Name" />
                <p:inputText id="Latin" value="#{smPestsList.latinName}"
                    label="Latin name" />
                <h:outputLabel for="Recog" value="Image Recognition" />
                <p:selectOneMenu id="selectOne">
                    <f:selectItem itemLabel="" itemValue="" />
                    <f:selectItem itemLabel="SEGMENTATION" itemValue="1899" />
                    <f:selectItem itemLabel="R-CNN" itemValue="1900" />
                    <f:selectItem itemLabel="NONE - COPY MARKINGS" itemValue="1951" />
                </p:selectOneMenu>


                <f:facet name="footer">
                    <p:commandButton value="Search"
                        action="#{smPestsList.searchButton}" icon="ui-icon-check"
                        update=":pestsList:pestsTbl" />
                    <p:commandButton value="Search and Izpis"
                        action="#{smPestsList.pestsNames}" icon="ui-icon-check"
                        update=":pestsList:pestsTbl" />
                    <p:commandButton value="Search and Izpis arg"
                        action="#{smPestsList.pestsName(74)}" icon="ui-icon-check"
                        update=":pestsList:pestsTbl" />
                    <p:linkButton outcome="SmPestsEdit" value="Add"
                        style="margin-right:20px;">
                    </p:linkButton>
                    
                </f:facet>
            </p:panelGrid>

        </p:panel>

        <p:dataTable id="pestsTbl" var="zuzek" value="#{smPestsList.pests}" editable="true"
            style="margin-bottom:40px">
            <f:facet name="header">
           PESTS
       </f:facet>
            <p:column headerText="Id">
                <h:outputText value="#{zuzek.idPest}" />
            </p:column>
            <p:column headerText="Code">
                <h:outputText value="#{zuzek.code}" />
            </p:column>
            <p:column headerText="Latin Name">
                <h:outputText value="#{zuzek.latinName}" />
            </p:column>
            <p:column>
            <p:linkButton outcome="SmPestsEditable" update="pestsListEdit" value="Edit" style="font-size:3em" title="edit">
                <f:param name="id" value="#{zuzek.idPest}" />
                <f:param name="code" value="#{zuzek.code}" />
                <f:param name="lname" value="#{zuzek.latinName}" />
            </p:linkButton>
            <p:button outcome="SmPestsEditable" icon="pi pi-trash" style="margin-right:5px;" title="delete">
                <f:param name="id" value="30" />
            </p:button>
            </p:column>
        </p:dataTable>


    </h:form>
</h:body>
</html>

SmPestList.java:

package si.david;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityResult;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.FieldResult;
import javax.persistence.Query;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.TypedQuery;

import si.david.SmPests;
import si.david.SmPestsNames;

import org.hibernate.annotations.CreationTimestamp;
import org.junit.Before;
import org.primefaces.event.RowEditEvent;
import org.primefaces.event.SelectEvent;

    @Named(value="smPestsList")
    @RequestScoped
    public class SmPestsList {
    private List<SmPests> pests = new ArrayList<SmPests>();
    
    private EntityManager em =null;
    private EntityManagerFactory emf = Persistence.createEntityManagerFactory("tvTutorialPU");
    private int idPest;
    private String latinName;
    private String code;
    private String srpName;
    private Long srpId;
    private String fraName;
    private Long fraId;
    private String itaName;
    private Long itaId;
    private String engName;
    private Long engId;
    private String espName;
    private Long espId;
    private String deuName;
    private Long deuId;
    private String magName;
    private Long magId;
    private String porName;
    private Long porId;
    private String ukrName;
    private Long ukrId;
    private List<SmPestsNames> smPestsNames = new ArrayList<SmPestsNames>();
    
    public void searchButton() {
        EntityManager em =null;
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("tvTutorialPU");
        em = emf.createEntityManager();
        String query;
        SmPests zuzek1 = new SmPests();
        int parametri = 0;
        if(!code.isEmpty())  {
            parametri++;
        }
        if(!latinName.isEmpty())  {
            parametri++;
        }
System.out.println("parametri:" + parametri);           
        query ="SELECT DISTINCT s FROM SmPests s";
        if( getCode() != null && !"".equals(getCode()) ) {
            parametri ++;
        }
        if( getLatinName() != null && !"".equals(getLatinName()) ) {
            parametri ++;
        }               

        if(parametri >0) {
            query = query + " WHERE ";
            if( getCode() != null && !"".equals(getCode()) ) {
                parametri --;
                query = query +"(code LIKE UPPER('%" + getCode() + "%') OR code LIKE UPPER('" + getCode() + "%'))";
            }
            if( getCode() != null && !"".equals(getCode()) && getLatinName() != null && !"".equals(getLatinName()) ) 
                query = query + " AND ";
            if( getLatinName() != null && !"".equals(getLatinName()) ) {
                parametri --;
                query = query + "UPPER(latinName) LIKE '" + getLatinName() + "'";
            }
        }
        System.out.println("query: " + query);
        try {
            List<SmPests> results = em.createQuery(query,SmPests.class).getResultList();    
            for(SmPests s : results) {
                SmPests zuzek = new SmPests();
                zuzek.setIdPest(s.getIdPest());
                zuzek.setCode(s.getCode());
                zuzek.setLatinName(s.getLatinName());
                try  {
                    List<SmPestsNames> imena = zuzek.getSmPestsNames(); 
                    for(SmPestsNames t : imena) {
                        System.out.print(t.getIdPestName());
                        System.out.print(" | "+t.getIdLanguage());
                        System.out.println(" | "+t.getName());
                        }
                }  catch (Exception e)   {
                    System.out.println("Oops");
                }

                pests.add(zuzek);
        }} catch (Exception e) {
            System.out.println("doesn’t work”);
        }   
        
}
    public void izpisime() {
        System.out.println("pest data: ");
    }
    public void pestsName(int id) {
        EntityManager em =null;
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("tvTutorialPU");
        em = emf.createEntityManager();
        String query;
        SmPests zuzek = em.find(SmPests.class,id);
        query ="SELECT DISTINCT s FROM SmPestNames s";
        try  {
            List<SmPestsNames> imena = zuzek.getSmPestsNames(); 
            for(SmPestsNames s : imena) {
                if(s.getIdLanguage()==1) {
                    sloId=s.getIdPestName();
                    sloName=s.getName();
                }
                System.out.print(s.getIdPestName());
                System.out.print(" | "+s.getIdLanguage());
                System.out.println(" | "+s.getName());}
        }  catch (Exception e)   {
            System.out.println("pesetsName(int id) doesn’t work");
        }
    }
    private SmPests loadPestById(int id) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("tvTutorialPU");
        EntityManager em = emf.createEntityManager();
        SmPests zuzek = em.find(SmPests.class, id);
        System.out.println("naslooo");
        try  {
            System.out.print(zuzek.getIdPest());
            System.out.print(" | "+zuzek.getCode());
            System.out.print(" | "+zuzek.getLatinName());
            System.out.print(" | "+zuzek.getImgRecognition());
        }  catch (Exception e)   {
            System.out.println("Can’t fin pest id: " + id);
        }
        return zuzek;
    }
    private SmPestsNames loadNamesById(int id) {
        System.out.println("loading pest");
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("tvTutorialPU");
        EntityManager em = emf.createEntityManager();
        
SmPestsNames imena = em.find(SmPestsNames.class, id);
        System.out.println("naslooo");
        try  {
            System.out.print(imena.getIdPestName());
        }  catch (Exception e)   {
            System.out.println("Ni bla- ja!");
        }
        return imena;
    }
    
}

java – Single DB – Multitenancy with microservices

We are migrating from a monolith to microservice.

Note : We store the tenant details in master tenant db which is seperate from the application database

As-is:

  1. The app serves multiple tenants and has around 10 sub modules which are tightly bound.

  2. We are splitting the 10 sub modules into 10 different services and planning to use single database for all the sub modules.

  3. There are around 20 tables in a single database without references.

Plans to:

  1. Keep the connection establishment , model , DTO , response classes (all common classes for all modules are placed in a base class)
  2. Add the base class as a dependency module for all the other 10 sub-modules.

I have the following question for which I couldn’t get any proper responses while surfing the internet.

1) Is the above `Plan to` a valid approach ?
2) Will each sub-module try to make its own connection ? 
3) How to address the issue of base class becoming huge and is duplicated in all sub-modules ?
4) Will this cause any deadlocks since each service will connect to same db at any given time ? 

Thanks in advance.

java – Memory keeps getting drained by buff/cache

I often find my system memory running quite low, even when doing relatively minor tasks, like browsing the web or gaming.

I am running on Ubuntu 20.04 with Unity DE (Also happened Ubuntu 18.04 on GNOME and LXQt). I have 8 GB of RAM and 8 GB of Swap to give some time to react to memory draining. This happened both before and after complete re-install of the operating system.
Both keep slowly filling up to 100%, which is when my system freezes and can stay unusable anywhere from 5 minutes to 2 hours, before the responsible programs eventually crash. This is rather inconvenient.

So far I’ve found 3 programs that can cause this to happen, Google Chrome and 2 games, M&B Warband and Minecraft. Oddly enough, Firefox does not have this same issue, and I use it a lot more than Chrome. This can also happen with only one tab loaded in Chrome.

When I close the program that seemingly caused this to happen, the memory is immediately freed and can be used again. In the case of Minecraft, limiting the memory usage with JVM arguments has no effect (Tried both OpenJDK and Oracle JRE without any difference).

When looking into this, I found that most of the memory is not actually being taken by any visible program, instead it goes into buffer/cache. And this does not appear to be just “borrowed” memory that would be released when needed, since the system will freeze instead of freeing the memory.
Using a command like echo 3 > /proc/sys/vm/drop_caches has no effect at all. The only way to free the memory is by closing whatever program was causing this.

Any clue what could be causing this and how to make it not happen again? It is rather inconvenient.

Edit: I also tried to cap dirty cache, as suggested by Very high cache usage causing slowdown but it had no notable effect on the problem.

java – com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Local ejb-ref name=web.DataSession/db,Local 3.x

In an attempt to inject an EJB into a SessionScoped bean which is called by a jsf page It throws an exception.

My EJB:

@Stateful
public class DataBean {
    Configuration c = new Configuration().configure().addAnnotatedClass(Profession.class);

    SessionFactory sf = c.buildSessionFactory();

    Session s = sf.openSession();

    public void createProf() {
        Profession p = new Profession();
        p.setProfession_name("professionname");
        p.setProfession_description("professiondesc");
        s.save(p);
    }
}

My SessionScoped BEAN:

@Named
@SessionScoped
public class DataSession implements Serializable{
    private static final long serialVersionUID = 125125125L;
    @EJB
    private DataBean db;
    
    private String name;
    private String desc;
    
    public DataSession() {}
    
    @PostConstruct
    public void createProf() {
        db.createProf();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
    
    
}

Called from JSF like this:

<h:form> <h:inputText value=”#{dataSession.name}”/> <h:inputText
value=”#{dataSession.desc}”/> <h:commandButton
action=”#{dataSession.createProf()}” value=”Add”/> </h:form>

ANd this is the Exception and it is really long(half of the exception beacuse it wouldnt let me post all):

java.lang.IllegalStateException: Exception attempting to inject Local
ejb-ref name=web.DataSession/db,Local 3.x interface =ejb.DataBean
resolved to intra-app EJB DataBean in module
worker,ejb-link=DataBean,lookup=,mappedName=,jndi-name=,refType=Session
into class web.DataSession: Lookup failed for
‘java:comp/env/web.DataSession/db’ in
SerialContext(myEnv={java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,
java.naming.factory.url.pkgs=com.sun.enterprise.naming} at
org.glassfish.weld.services.InjectionServicesImpl.aroundInject(InjectionServicesImpl.java:151)
at
org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:46)
at
org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:71)
at
org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:117)
at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:159) at
org.jboss.weld.util.bean.IsolatedForwardingBean.create(IsolatedForwardingBean.java:45)
at
org.jboss.weld.contexts.AbstractContext.get(AbstractContext.java:96)
at
org.jboss.weld.contexts.PassivatingContextWrapper$AbstractPassivatingContextWrapper.get(PassivatingContextWrapper.java:76)
at
org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)
at
org.jboss.weld.bean.ContextualInstanceStrategy$CachingContextualInstanceStrategy.get(ContextualInstanceStrategy.java:177)
at
org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
at
org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:676)
at
org.jboss.weld.module.web.el.AbstractWeldELResolver.lookup(AbstractWeldELResolver.java:107)
at
org.jboss.weld.module.web.el.AbstractWeldELResolver.getValue(AbstractWeldELResolver.java:90)
at
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:147)
at
com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:156)
at
com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:184)
at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:92)
at com.sun.el.parser.AstValue.getBase(AstValue.java:126) at
com.sun.el.parser.AstValue.getValue(AstValue.java:175) at
com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:202)
at
org.jboss.weld.module.web.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at
com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:73)
at
javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:170)
at
javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:157)
at javax.faces.component.UIOutput.getValue(UIOutput.java:140) at
javax.faces.component.UIInput.getValue(UIInput.java:287) at
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:181)
at
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:328)
at
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:143)
at
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:595)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1654)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:152) at
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:566)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1647)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1650)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1650)

java – “illegal start of expression” em PessoaDAO

Estou com esse erro no meu PessoaDAO:

package com.example.pim8;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public class PessoaDAO {

    private conexao Conexao;
    private SQLiteDatabase banco;

    public PessoaDAO(Context context) {
        Conexao = new conexao(context);
        banco = Conexao.getWritableDatabase();

        public long inserir (Pessoa **pessoa**){

            ContentValues values = new ContentValues();
            values.put ("nome", **pessoa**.IdNome());
            values.put("cpf", **pessoa**.IdCpf());
            values.put("encereco", **pessoa**.IdEndereco());
            values.put("DDD", **pessoa**.IdDdd());
            values.put("telefone", **pessoa**.IdTelefone());

            return banco.insert("pessoa", null, ContentValues);

        }

    }
}

Aparentemente ele não reconhece pessoa

Alguém pode me ajudar?

java – Error clase Point para calcular puntos en eje

public static void main(String() args){

int x1 = -2;
int y1 = 1;  
int x2 = 3;
int y2 = 3;  
Point p1 = new Point(x1,y1);
Point p2 = new Point(x2,y2);
Point origen = new Point();

double dist1 = Math.sqrt(p1.x * p1.x + p1.y * p1.y);
double dist2 = Math.sqrt(p2.x * p2.x + p2.y * p2.y);

System.out.println("El punto que se encuentra máxima distancia es: Math.max(dist1,dist2) ");

     

    }
}

He probado esto, he probado a poner public class Point como también aparece en la librería pero nada, no encuentro el error, el error que muestra y se describe cómo:
introducir la descripción de la imagen aquí

El objetivo es calcular dos puntos y decir cuál es más lejano respecto al eje (0,0) pero no entiendo el error:

“La clase tiene que ser compilada para configurar breakpoints” y me salen como 10 avisos de error pero es porque falla algo pero no sé el qué.

Muchas gracias.

java – Is calling Session::evict() on Hibernate entities considered bad practice?

I’m using Hibernate in my application. When calling the setters on Hibernate entities that are in “managed” state, it will eventually write the changes back to database when the transaction is getting committed, even without explicitly calling Session::update().

Sometimes, I have to call Session::evict() in my code to avoid accidentally writing these changes into database. However, I have some problems:

  • I have to worry about the state of these entities all the time. When passing entities between services and DAOs, I need to keep track of the states of them. This increase the complexity of development.
  • Writing test cases became harder. Asserting the state of entities that must be “managed” or “detached” state is tedious and annoying.

Is calling Session::evict() considered bad practice? If so, what’s the best way to avoid it?

web application – API Returning Java Exception. Safe?

I just wanted to ask if my concerns here are valid.

I am aware that it is unsafe for the api to return a stacktrace.

The question I have is whether there is also some standard regarding packaging up java exceptions into a 500 response and telling them only that. I am talking about sending back such things as “DataIntegrityViolationExceptio”, “NullPointerException” etc. Is this a good idea? Or should it be more generic than this?

I am currently warning folks against this and that they should “whitelist” their server responses (i.e. only send it if you have a conscious reason or are forced to by). I just wanted to know if I am wasting our time with this.

Thank you for any input on this.

java – Como realizar uma instalação sem interação do usuário no formato. jar através de um bat?

Obrigado por contribuir com o Stack Overflow em Português!

  • Certifique-se de responder à pergunta. Entre em detalhes sobre a sua solução e compartilhe o que você descobriu.

Mas evite

  • Pedir esclarecimentos ou detalhes sobre outras respostas.
  • Fazer afirmações baseadas apenas na sua opinião; aponte referências ou experiências anteriores.

Para aprender mais, veja nossas dicas sobre como escrever boas respostas.

design – Java: Splitting a large unit test class

The project (Java/Spring) I currently work on has a rather large unit-test class for one of its services : more than 1000 lines, several Nested class (one per big functionality), some tests without a Nested class, …

Finding this file rather difficult to read, and to manage (a modification in the service, and you have to take time to find the corrects tests to fix/update), I proposed to split the class to have one test file per Nested Class, each one linked to a “principal” test file, which will be managing the Mock & the tests without Nested Class. All the tests files would be put into a specific package.

I am wondering if this would be a good thing to do? or if it was something to avoid to do ?

I hope i was clear enough.
Have a nice day