Posts by Felipe Marinho • 2,873 points
108 posts
-
2
votes3
answers253
viewsA: Refactor code using Factory Pattern without using the if-elseif condition
You could use a enum with one element for each type of parser. In it you would have the way parser is created and the Pattern corresponding. Example: Class InvoiceParser: private abstract class…
-
1
votes1
answer633
viewsA: JPA insert an object that has a list as attribute
The method persist class EntityManager expects an entity (class annotated with @Entity) as an argument, but in the em.persist(listaFornecedores) you’re passing a ArrayList which, although it…
-
1
votes2
answers677
viewsA: Java regex help - comma-separated sequence of numbers
Use the Pattern /aluno/\\d+?/\\D+?/(\\d+?,)*?\\d+. (\\d+?,)*? => 0 or more consecutive decimal; \\d+ => a last number which is not followed by a comma. Example: String t1 = "/aluno/1/Teste dos…
-
0
votes1
answer28
viewsA: Eclipse has stopped claiming the need to declare the serial default Version ID. in the serialized classes
Go to Window -> Preferences -> Java -> Compiler -> Errors/Warnings -> Potential Programing Problems. Then just locate the option "Serializable class without serialVersionUID" and…
-
3
votes1
answer180
viewsA: How to add elements of two streams in java?
There is no function similar to zipWith in the API of Streams of Java. It was implemented in a build of Java 8 but it was removed because, in the view of those responsible for the language, such…
-
1
votes1
answer117
viewsA: How to convert a Jsonarray to a Strings array?
You need to separate the String greater in Strings smaller by the separator (",") before passing it to the Arrays.asList(...) using the method split(String). Also, you should remove the quotes:…
-
0
votes1
answer978
viewsA: Map json using Jackson
The method readEntity(Class<T> entityType) can only be used once per response, since when it is executed, the input stream is consumed and the connection is closed (if the response is read as…
-
0
votes1
answer37
viewsA: String replace is not performing swap
Substitute ch == entry.getKey() for ch.equals(entry.getKey()). == checks whether the two references point to the same instance of an object. Already the method implementation equals in class…
-
1
votes2
answers919
viewsA: JSON Infiito when using GET @Manytomany
Use the annotations JsonManagedReference and JsonBackReference. They are used to indicate that such properties are part of a bidirectional relationship. The first should be used in the class…
-
2
votes1
answer459
viewsA: Properly manage database connections using Hibernate
This will depend on the application: whether it will support a user or multiple users simultaneously; whether it will use one or multiple threads; application architecture; if any framework that…
-
1
votes2
answers100
viewsA: How is it still possible to calculate 1<<64-1 without issuing an overflow?
This is because the value 1<<65-1<<64-1) is not treated as a uint64 during the execution, but as a Constant Expression during the compilation, and may contain only Constants. According…
-
2
votes1
answer112
viewsA: Elixir multiplication on a Map does not work. Why?
Both codes work properly, as can be seen here. The problem you are facing occurs when displaying the results. When you use it IO.inspect in a collection of integers, Elixir tries to convert these…
-
2
votes2
answers318
viewsA: Enum getting next code in Java
When Jackson will deserialize a JSON and the properties AUTO_DETECT_GETTERS and AUTO_DETECT_SETTERS are at the value true (standard value), the setters/getters of its object are used to populate it…
-
1
votes2
answers825
viewsA: Lambda in Java 8 launching Exception
The problem is here: //... user.ifPresent(u -> { //... group.orElseThrow(() -> new Exception("Grupo não encontrado")); //... }); //... When using a lambda in this case, you are passing to the…
-
3
votes1
answer442
viewsA: Events of jQuery Vs. Arrow functions?
To Arrow Function works with jQuery, what doesn’t work is the $(this). This is not implementing by jQuery because is not possible. Arrow functions don’t have their Own this Binding so it’s…
-
1
votes3
answers320
viewsA: Where to put the files?
Each IDE/Build Tool has its own way of structuring a Java project, some are more rigid, others more flexible. The folders you mentioned will not be present in the same project, since they are part…
-
1
votes2
answers373
viewsA: How to generate a RSA key pair in Windows 10?
Go has a tool for you to generate keys. Open Command Terminal and do the following: > cd %GOROOT%\src\crypto\tls > go run generate_cert.go --host localhost --ca true //Substitua C:\ pelo local…
-
3
votes1
answer210
viewsA: Error with Hibernate query
In his query, you are calling the parameter of :hoje. However, by evoking the method setParameter, you use the name dtinicio. Change that: .setParameter("dtinicio", hoje) For that reason:…
-
1
votes1
answer671
viewsA: Java - Read file and Write output to . txt
You are creating the file within the loop while. This causes each iteration to create a new file and overwrite the previous one. To resolve the problem, just move the file startup and the closure…
javaanswered Felipe Marinho 2,873 -
0
votes1
answer109
viewsA: How to print only numbers that repeat between two different lists?
Use the method retainAll(Collection<?> c): public class RetainsAll { public static void main(String[] args) { List<Long> lista1 = new ArrayList<>(); List<Long> lista2 = new…
javaanswered Felipe Marinho 2,873 -
1
votes1
answer87
viewsA: Error creating Hibernate tables
That is the mistake: Row size Too large. The Maximum Row size for the used table type, not Counting Blobs, is 65535. This includes Storage overhead, check the manual. You have to change some Columns…
-
2
votes2
answers70
viewsA: File still in use by Java / How to close file connection
Use the Try-with-Resources to close the InputStream: try (InputStream imagemStream = new FileInputStream(new File("D:\\movie_play_red.png"))) { image = new Image(imagemStream, 150, 0, true, true);…
-
2
votes1
answer940
viewsA: Use a java Resultset to print an entire table on the screen
It doesn’t exist, but the ResultSet has methods to create such functionality. Example: public class ResultSetExibirTabela { public static void main(String[] args) throws SQLException { //Coloque as…
-
4
votes2
answers458
viewsA: Sort a java List containing null values
You can use the method nullsLast class Comparator: Class Objeto: public class Objeto { private int numero; private String palavra; private LocalDate data; public Objeto(int numero, String palavra,…
-
0
votes1
answer63
viewsA: Problem in table name during creation by Hibernate
Use the annotation @AssociationOverride. Example: Class Menu: @Entity public class Menu { @Embedded @AssociationOverride(name="status",joinTable=@JoinTable(name="menu_share_activity")) private…
-
1
votes1
answer1299
viewsA: Create Trigger after update in the table itself and in another table
Just use the BEFORE UPDATE: CREATE TRIGGER trigger_alecrim_update BEFORE UPDATE ON alecrim FOR EACH row SET NEW.totOvos = NEW.p1 + NEW.p2 + NEW.p3 + NEW.p4 + NEW.p5 + NEW.p6 + NEW.p7 + NEW.p8 +…
-
0
votes1
answer411
viewsA: How to take the value of a tag and send it to another tag with js
First of all, two observations: all your tags img have the same value in the attribute id. According to the specification html, the value of that element must be unique. These values should be in…
-
2
votes2
answers1498
viewsA: How to delete all untracked files at once in git?
You can use the command git clean -f. In case you want to check which files would be deleted before performing the deletion, you can use the option -n, example: git clean -n The exit would be: Would…
gitanswered Felipe Marinho 2,873 -
1
votes1
answer58
viewsA: Problem when performing a select with JPA
You are closing your EntityManager after changing the data of the Apartamento: public void alterarAp(Long numero, long andar, String descricao, BigDecimal valor, Long quantidade, String ala) {…
-
1
votes1
answer244
viewsA: What is the problem with this java class that consumes a Rest service?
The schema of the JSON you are trying to deserialize does not correspond to the interface structure you have assembled. Its interface Art corresponds to an element of the array called all, that is…
-
1
votes1
answer470
viewsA: How to cascade relationship?
You can use the method <T> T merge(T entity) instead of void persist(java.lang.Object entity). It is used to link entities that are in the state Detached (entities that may or may not exist in…
-
0
votes1
answer87
viewsA: Jaxb and JPA: class Embeddable Could not determine type for java.util.List
You are mixing different AccessType in the same class. In the top level class LoteRpsV3Vo you are using AccessType.PROPERTY (getters annotated), so Hibernate expects to find the annotations in…
-
0
votes1
answer593
viewsA: Webservice Jersey REST Not Found
The Problem is here: <init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>br.com.webservice.resources</param-value>…
-
1
votes1
answer58
viewsA: Error creating database with Hibernate and Spring MVC
In his CategoriaController, you must change this passage: @Autowired private CategoriaDao categoriaDao; To: @Autowired private DAO<Categoria> categoriaDao; Whenever you inject a component,…
-
2
votes1
answer65
viewsA: Using Fileserver to share files
When you run your go code, Windows will ask you for permission so that other devices on your private network can access that port (8080). All you have to do is allow her to be accessible. When…
-
2
votes1
answer352
viewsA: Callback methods annotated in a Listener bean class must Return void and take one argument: javax.persistence.Preupdate
Caused by: javax.persistence.PersistenceException: Callback methods annotated in a listener bean class must return void and take one argument That’s what the message says. Your methods noted with…
-
2
votes3
answers1291
viewsA: Optimize HTML video 5
You can place your video to load after the page and all its contents are loaded. Example: <html> <head> <script…
-
9
votes2
answers3969
viewsA: How to remove all Classes from an element using jQuery?
Just use the method removeClass parameter-less: $("#div").removeClass(); Documentation…
-
0
votes1
answer75
viewsA: What would the @DELETE methods of a Restfull java api look like?
According to the documentation of Deltaspike, the method remove evokes the method remove class EntityManager. Like the method of the last spear a IllegalArgumentException if it fails, you could try…
-
2
votes2
answers35
viewsA: Select does not select the correct value
The attribute selected is a boolean value indicating which of the options should be selected. If there are multiple tags option with the property selected, the last will be selected. As you want to…
-
0
votes3
answers320
viewsA: convert value to 2 decimal places in JS
You could manipulate the value as a number, rather than a String. Example: var numero = Number("22101000000"); if(numero >= 1000000000 && numero < 1000000000000) { var numeroReduzido =…
javascriptanswered Felipe Marinho 2,873 -
0
votes1
answer52
viewsA: Response and Request format
You can do this in some ways, including the one you mentioned. Using a new class The first option is to create a new class (a kind of Object Adapter) with the same attributes with the desired names.…
-
0
votes1
answer455
viewsA: Spring + Javascript
To Expression language is processed on the server side. In the section below, when you use the expression ${tipopagamento}, the server will invoke the method toString of the class and pass as…
spring-mvcanswered Felipe Marinho 2,873 -
1
votes2
answers151
viewsA: Help in code printing of repeated characters
It’s simpler, in this case, to transform the String in a array characters. And also remove characters from String that have already been verified so that they are not counted multiple times. String…
-
0
votes1
answer72
viewsA: Take text from a website span and return to the console
You can use the library jsoup for this. Example: to catch all the spans of google, you could do it this way: Document doc = Jsoup.connect("https://www.google.com").get(); doc.select("span")…
javaanswered Felipe Marinho 2,873 -
0
votes3
answers1096
viewsA: Getting a binary file and saving it again
Java 6 or less In versions earlier or equal to Java 6 you can do so: File original = new File("c:\\farol.jpg"); if(!original.exists()) { throw new IOException("O arquivo especificado não existe!");…
-
1
votes1
answer604
viewsA: Search using Criteria with WHERE, AND and OR
Criteria In that case, it is simpler to use the clause IN than the clause OR. So, your Criteria would look that way: // parametros Set<String> marcas = new HashSet<>();…
-
6
votes3
answers3811
viewsA: Unparseable date: "2017-10-30T02:00:00.000Z"
The Pattern used in the SimpleDateFormat has to represent the format of the date you receive. Instead of: SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy"); Use: SimpleDateFormat formato…
-
4
votes1
answer158
viewsA: How to compare relative run time of fast algorithms?
The only way to eliminate the time consumed by the loop is by eliminating the loop itself and running the desired code. The problem with this is that, as the algorithm tested is usually so fast, it…
-
0
votes2
answers725
viewsA: Solution of exceptions Serviceexception and Failed to execute Goal org.codehaus.mojo:exec-Maven-plugin:1.2.1:exec?
When using versions of driver mysql-connector-java above 6.0, you need to inform the property serverTimezone with the desired value in your javax.persistence.jdbc.url. Change that: <property…